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

...
If you use Alpine distributions, you could not have a bash.

in this case, you can use sh:
`docker exec -it <container_id> sh`

As an alternative, you can install the bash in the Dockerfile.

...
Another use Case

If you use Postgres and you wanna see the database directly from the Postgres container is:

`docker exec -it <container_id> psql -U Postgres

• • •

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

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
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
27 Apr
What is a Docker container?

The easiest way to understand what a container is is to think of it as a process that runs on our machine, isolated from other processes.

To make this happen, Linux namespaces and cgroups are used under the hood.

... 1/4
A container has its own dedicated filesystem, provided by an image.

The image contains:

-dependencies
-configuration
-binaries
-environment variables
-other important data related to the container to be instantiated.

Many containers can be run from a single image

... 2/4
Technically, a container is first created, then, started.

To do this with a single command, we can use the 'docker run' command.

to see all the containers running on the host:
'docker container ls -a'

or just
'docker ps -a'

... 3/4
Read 4 tweets
26 Apr
DOCKERFILE:

What is it?
A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image.

In other words, a Dockerfile allows you to avoid writing each command one by one in a super simple way

... 1/25
FORMAT:

The format of a Dockerfile is simple:

# Comment
INSTRUCTION args
INSTRUCTION args
INSTRUCTION args

The instruction is not case-sensitive, but the convention is to be UPPERCASE to distinguish them from arguments more easily.

add # to add a single-line comment

... 2/25
.dockerignore

Before sending the context to the Docker daemon, the Docker CLI checks if a .dockerignore file is in the root directory. If so it excludes files/dirs that match patterns in it.

It works in a similar way of the .gitignore

... 3/25
Read 25 tweets
23 Apr
Docker Architecture

Docker uses a client-server architecture.

The Docker client talks to the Docker daemon (server), which menages different docker objects:
- Images
- Containers
- Networks
- Volumes

Let's see in details:

... 1/12
The Docker client and the daemon can run on the same system, or they can be connected remotely using HTTP protocol.

The connection is established using REST APIs, over UNIX sockets/network interface

... 2/12
DOCKER DAEMON (SERVER)

The Docker daemon (dockerd) is a process, which runs in the background, that manages the docker objects (images, containers, networks, volumes). It processes Docker API requests

... 3/12
Read 12 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!

:(