2023-08-24 10:23:28 +00:00
# my_ros2_docker_image
2023-10-23 08:56:31 +00:00
This template repository should give a good overview on how to build your own ROS2 development instance and produce a new hosted docker image out of it.
2023-10-23 12:50:56 +00:00
For now the steps below are only suited for a existing Ubuntu installation. Windows is for now not supported in this repository.
2023-08-24 10:23:28 +00:00
2023-10-23 12:49:10 +00:00
## Install dependencies needed for working with docker images and tools to make your life easier
2023-10-23 12:49:26 +00:00
Using the official Docker convenience installer script, we will install docker and docker compose:
2023-10-23 12:49:10 +00:00
```
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
```
Then add yourself to the docker group so you must not always use sudo when tinkering with docker commands:
```
sudo groupadd docker
sudo usermod -aG docker $USER
```
Update the group changes:
```
newgrp docker
```
Source: https://docs.docker.com/engine/install/ubuntu/#install-using-the-convenience-script
2023-10-23 11:50:15 +00:00
## Simple build
First things first: Let's begin with a short and simple build. This is a short hello, world! example.
### Clone this repository to your local machine
```
git clone https://github.com/bjoernellens1/ros2_docker_template
```
### Build the hello, world! image
```
docker buildx bake hello-world --load # to load into local container registry
```
2023-10-23 11:54:22 +00:00
or
2023-10-23 11:50:15 +00:00
```
docker buildx bake hello-world --push # to push into specified remote container registry
```
2023-10-23 11:54:22 +00:00
### Run the hello, world! image
```
docker compose run hello-world
```
2023-08-24 10:23:28 +00:00
2023-10-23 12:18:30 +00:00
## Advanced build: Custom ROS2 image that includes the Unitree GO1 package.
2023-10-23 08:30:09 +00:00
```
2023-10-23 08:59:45 +00:00
docker buildx bake my_example --load # to load into local container registry
2023-10-23 08:30:39 +00:00
```
2023-10-23 12:18:30 +00:00
or
2023-10-23 08:30:39 +00:00
```
2023-10-23 08:59:45 +00:00
docker buildx bake my_example --push # to push into specified remote container registry
2023-10-23 08:30:09 +00:00
```
2023-10-23 08:59:45 +00:00
## To run my_example:
2023-10-23 09:41:35 +00:00
### Run my_example just once to see if everything's working:
2023-10-23 12:18:30 +00:00
This will launch the Unitree udp high-level control node.
```
docker compose run my_example
```
2023-10-23 08:59:45 +00:00
### Run my_example in background
2023-10-23 08:30:09 +00:00
```
2023-10-23 09:41:35 +00:00
docker compose up -d my_example
2023-10-23 08:30:09 +00:00
```
2023-10-23 08:59:45 +00:00
### Run my_example in foreground
2023-10-23 08:30:09 +00:00
```
2023-10-23 09:41:35 +00:00
docker compose up my_example
2023-10-23 08:30:09 +00:00
```
2023-10-23 08:59:45 +00:00
### Execute shell inside my_example
2023-10-23 08:28:10 +00:00
#### If container is stopped
2023-10-23 08:30:09 +00:00
```
2023-10-23 08:59:45 +00:00
docker compose run my_example bash
2023-10-23 08:30:09 +00:00
```
2023-10-23 08:28:10 +00:00
#### If container is already running
2023-10-23 08:30:09 +00:00
```
2023-10-23 08:59:45 +00:00
docker compose exec my_example bash
2023-10-23 08:30:09 +00:00
```
2023-10-23 08:59:45 +00:00
### Execute example_program inside my_example
2023-10-23 08:30:09 +00:00
```
2023-10-23 08:59:45 +00:00
docker compose run my_example example_program
2023-10-23 08:30:09 +00:00
```
2023-10-23 12:55:35 +00:00
You will find that example_program does not exist. Try using rqt for example:
```
docker compose run my_example rqt
```
2023-10-23 11:50:15 +00:00
## Next steps
### Fork this repository and make it your own
### What you will want to change in your repository:
#### my.repos and my_extended.repos:
These are yaml files containing the repositories you may want to include into your final ros2 workspace.
For a multi-stage build for instance, I define my base image repositories in "my.repos" and the extended image repositories in "my_extended.repos"
2023-10-23 12:42:12 +00:00
## Additional Resources
For further references please visit my WIP repositories for mobile robotic platforms:
- https://github.com/bjoernellens1/ros2_rmp
- https://github.com/bjoernellens1/cps_bot_mini_ws