Docker guide
This guide aims to give some insights about running Docker containers, volumes and networks directly using docker run
.
๐ซ This page does not aims to be a comprehensive Docker tutorial, see the official documentation if you want to know more about Docker.
#
Basic Docker commands#
Run a containerA Docker image can be run to create a container in 2 ways
-it
Interactive: the process is attached to the terminal and you can stop it using ctrl+C-d
Detached: the process is detached and will continue if you exit the terminal.
#
Stop a containerTo get a Docker container ID and stop it:
Automatically delete a container after run
You can use the --rm
flag to automatically delete a container after its run. It avoid accumulating containers and wasting memory.
#
Share volumesA lot of images will require input files, the best way to provide them is to share a volume from your system to the container. It can be done by using -v
when docker run
.
Let's say I have a /data/d2s-workspace/my-file.txt
on my system, and I want to provide it as a container input file.
- I need to provide he
-v
flag with paths separated by a:
- before the user provide the path of the shared volume on his system
- after the user provide the path it will be accessible from in the Docker container
- In this example we are sharing the
/data/d2s-workspace
volume from our system to/data
in the Docker container. my-file.txt is then accessible as/data/my-file.txt
in the container
- Windows requires to provide the drive when sharing volume (e.g.
c:
) and the command to be one line.
- We usually provide a relative path using
$pwd)
To be tested on Windows.
#
Link and networkContainers can be linked using 2 ways: --link
flag and --network
.
#
NetworkEspecially used when running services using docker-compose. The --link
flag method can be easier to use in simple cases.
docker-compose.yml#
Example of a network setup in the#
Example of AutoR2RML connecting to the Drill container through a network#
Link--link
is deprecated, Docker recommends to use --network
. But the --link
flag can be more convenient to use in simple case: e.g. when linking to a single service, you just need to provide the container name instead of setting up a whole network.
#
How to use linkLet's say you have a frontend application that needs to query a backend application.
- Run the backend
- To access it as http://localhost:8080 in the frontend
- To access it as http://backend:8080 in the frontend
- You can link to multiple backend in a frontend