There’s a lot of new words / terms when it comes to Docker, the list below should serve a reference guide to get your terminology right ;).
Set up a dockerfile, starting off of a base image. From there you can run commands such as downloading, installing, or running your software. e.g.:
FROM ubuntu:16.04
RUN echo "WOOPWOOP I BUILT A DOCKER IMAGE"
Then build it, e.g.:
docker build -t myDockerImage .
Here, -t
defines the name of the image.
Then verify the images on the system using
docker images
Alternatively, you can just pull pre-existing docker images & use them)
docker pull myDockerImage:imageTag
image tags are often used to define different versions, e.g.: ubuntu:16.04
then just run it using
docker run myDockerImage
You can directly manage containers from within the command line interface (CLI). It is recommended to at least get to know the basic commands to understand the basic architecture of Docker, before moving to other options (see below). The reason for this is that the other options might not always work and will be cumbersome if you just want to do something quickly. Furthermore, most documentation makes use of the CLI, so learning this part is pretty much essential.
See what containers are currently available (-a
flag reveals also the inactive containers):
docker container ls -a
then to stop the container:
docker container stop DOCKER_ID
docker start DOCKER_ID
-i
and -t
flags (for more info type docker exec --help
).docker exec -it DOCKER_ID bash
bash docker run --name=DOCKER_ID myDockerImage
bash docker run --restart unless-stopped myDockerImage
docker run -d myDockerImage
docker run -p 1234:1234 myDockerImage
Define a volume (folder) for the container to use:
docker run -v /path/to/volume myDockerImage
Instead of using the CLI, using a GUI for Docker might be useful for a couple of reasons:
A very good option for this is Portainer.
Quick reference tutorial:
bash docker volume create portainer_data
bash docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce
localhost:9000
in your webbrowser.In here you can do everything you can do with CLI, and more, as long as the container is running.
With Docker compose you can set up more complex applications, spinning up multiple containers with the parameters you define in the docker-compose.yml
file.
As a (really simple) quick-reference example on how this is used:
mkdir compose_test
cd compose_test
nano docker-compose.yml
Then paste the following as an example docker-file.
version: '2'
services:
hello-world:
image: hello-world
restart: unless-stopped
To start the stack:
docker-compose up
To stop it:
docker-compose stop
To additionally remove the containers entirely run:
docker-compose down
Add the
--volumes
tag if you want to remove any data volumes you created with compose file.
For more info on commands you can run with compose, run:
docker-compose --help
You may want to change an existing docker image, and push it to some local registry that you have access to, so that you can share it with others, or access it more easily yourself. You can do this by using docker push.
Find the container you want to commit:
docker container ls
Commit it (tag is not always necessary)
docker container commit c16378f943fe new-image-name:some-tag-you-want-to-use
Then tag your commited container
docker image tag new-image-name:some-tag-you-want-to-use url-to-your-registry:some-tag-you-want-to-use
docker image push url-to-your-registry:some-tag-you-want-to-use
This registry can be a local registry server, or some cloud-hosted registry, like gitlab container registry.
One of the things Docker can be really useful for is for ROS. This comes in especially handy with ROS docker images provided by external parties. Providing an image is an easy way to ensure that everything works as it should, as long as you are running linux with docker installed. This way you won't have to worry about accidentally installing a non-compatible package / version, and it will prevent you from having to go and purge ROS from your system when things get really messed up (yes, this happens). Find the images here.
A collection of images you might find useful. Note that most of these have multiple images contained, which can be specified using tags
External:
Internal: