A diagram with some additional information below about the lifecycle of containers.
This is a simplified version, there are other commands (kill, ...) and other intermediate states
Let's see them:
docker create
Creates a new layer over an image with a writeable container.
It prepares it to run a specific command (the one specified in the Dockerfile)
Useful to set up a configuration so that it is ready to start when needed.
Status of the container: "CREATED"
docker start
Starts one (or more) container.
This command can either be used::
- To start a container just created with the docker create command
- To start a stopped container
docker run
Under the Hood, `docker run` are 2 commands:
docker create+docker start
- a container layer is created on the top of an image
- the container just created is started
It's important to understand this to avoid confusion between docker run/start/create
Docker RUN Common Options:
--name: assign a name
--rm: remove it when it exits
-p: publish ports
-e: set environment variable
-d: run it in the background
--network: connect it to a network
-i: keep stdin open
--mount: set a volume or bind mount
--user: set a user
docker stop
Stop one (ore more) container.
The main process inside the container will receive a SIGTERM, then a SIGKILL after some seconds.
The first signal can be edited:
- using the STOPSIGNAL instruction in the Dockerfile
- using the --stop-signal flag in "docker run"
docker pause
Pause all processes within one (or more) containers, suspending all the processes.
- On Linux, this uses the freezer cgroup.
- On Windows, only Hyper-V containers can be paused.
Usually, the SIGSTOP signal is used to suspend a process.
docker unpause
Unpause all processes within one (or more) container
On Linux, it does this using the freezer cgroup.
It un-suspends all processes in the specified containers.
docker rm
Remove one or more stopped containers
To remove a running container, use the -f (or --force) command
You can also remove anonymous volumes associated with the container with the -v option
• • •
Missing some Tweet in this thread? You can try to
force a refresh
There are many resources online, many great ones even free to learn Docker
But what is the path to learning Docker from Zero, so you can choose your own videos/articles?
Here is the path I suggest in 10 steps.
Let's see them together:
...
1) Understanding WHAT it is and what it isn't, what are the building blocks of it
2) Understanding what containerization is and why it is so important. Differences Containers/Virtual Machines
3) Install Docker on your operating system and make sure it works (`docker info`)
...
4) Take a look at "Docker Hub" and make a bit of practice using one image there (eg Nginx) and understand the basic commands: start/stop/list containers.
5) Understand how the components are made and their configuration: commands inspect/exec/logs.
-d: Run in detached mode
-e: Set new environment variable
--env-file: use an external file for env variables
-i: Keep the Standard Input open
-t: pseudo Terminal (TTY)
-u: define a user for the command
-w: define a working dir inside the container
...
The most common use case:
Use the exec command to get inside a running container
Example:
`docker exec -it <container_id> bash`
This works for most of the containers running based on Linux images
and me, because I create content about it every single day.
WHAT is Docker?
A container technology, a platform to build and manage containers.
You package the code with all the dependencies you need in order to run your application everywhere in a smart, reliable way.
Think about it as a Mountain Backpack, you can bring with you