Lifecycle of Docker containers (Thread)

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
 

Keep Current with Francesco Ciulla

Francesco Ciulla Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @FrancescoCiull4

22 May
What are dangling images in Docker?

Probably if you worked with docker locally, it happened to see something like this using `docker images`

The dangling images are those ones with <none> as [Repository] and [Tag]

Ugly uh?

Let me explain what's going on: a list of docker images, wi...
A dangling image is one that is not tagged and is not referenced by any container.

Why are they there?

Reasons could be different, but the most common case is when you build another image using the same tag

(Side note: don't build a production-ready image with the same tag)
To see just the dangling images on your system, you can use the command:

`docker images -f dangling=true`

what a good show, right? only images with <none> <none>
Read 5 tweets
20 May
I've dealt with a lot of negative comments in my life.

When I was a coach I got yelled at by people who didn't agree with my choices.

That's why IDGAF about a comment written by an anonymous user who hides behind a keyboard.

But someone does.

This thread could help you.
🧵 Image
1- Never take it personally:

Think they:

- had a bad day,
- just broke up,
- lost their job,
- got their car stolen
- their house went up in flames

But don't take this as a direct attack on you or your family.
2- Responding is usually more harmful than ignoring.

This does not mean that we must passively accept any accusation, but probably answering it will only fuel discussions.

Also, there are people who like to argue all day long.
That's their hobby.
Read 8 tweets
19 May
Path to Learn Docker in 10 steps.

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.

...
Read 7 tweets
18 May
The Computer Science degree helped me find a great job.

But not in the way you can imagine.

I always thought that after graduating in Computer Science I would immediately work as a freelancer, looking for clients and working remotely.

This was my plan.

But it changed.

👇
A University professor contacted me telling me that there was the possibility of working for the European Space Agency.

I was a bit torn but in the end, also out of curiosity, I went to the interview.

Two days later I got a great offer.

The next day I was working there.
This was a deviation from my initial project, but I adapted to this opportunity.

After about 4 years, and after leaving my 9-5 Job.

I don't regret my choice, which has given me stability and experience in the space sector, which I continue to love.
Read 5 tweets
18 May
docker exec

One of the most important CLI commands to debug/modify running containers on the Docker Host.

It runs a specific command in an already running container

Syntax:
docker exec [OPTIONS] <container_id> COMMAND [ARUMENTS...]

Example:
`docker exec 1234 echo "hi"`

...
Common options:

-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

...
Read 5 tweets
17 May
Docker 5 Ws:

Five Ws are questions whose answers are considered an information-gathering model.

So Docker:
-Who
-What
-Where
-When
-Why

WHO should you follow to learn Docker?
WHAT is Docker?
WHERE can you use Docker?
WHEN should you learn Docker?
WHY Docker?

A Thread:
WHO should you follow to learn Docker? (not in order)

Some great names who came to my mind now:
@BretFisher ,@mikesir87 , @Njuchi_ ,@lach_dev, @liran_tal ,@sidpalas ,@TechSquidTV ,@chriskalmar, @kelseyhightower

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
Read 6 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(