This guide aims to give some insights about running Docker containers, volumes and networks directly using
🚫 This page does not aims to be a comprehensive Docker tutorial, see the official documentation if you want to know more about Docker.
A Docker image can be run to create a container in 2 ways
-itInteractive: the process is attached to the terminal and you can stop it using ctrl+C
-dDetached: the process is detached and will continue if you exit the terminal.
To 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.
A 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
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
-vflag 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-workspacevolume from our system to
/datain the Docker container. my-file.txt is then accessible as
/data/my-file.txtin 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
To be tested on Windows.
Containers can be linked using 2 ways:
--link flag and
Especially used when running services using docker-compose. The
--link flag method can be easier to use in simple cases.
--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.
Let'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