Docker run

The `docker run` command is one of the most used commands when we use the docker CLI (Command Line Interface).

What does happen when we use it and which are the most used options? Check the docs!

But if you don't have time, let’ see it in 2 minutes:

1/12

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, docker start, and docker create

2/12
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

3/12
Assign a name (--name)

By default, a random name is assigned, but in general is a good idea to assign a custom name to our containers, as we do to our pets!

4/12
Remove the container when exits (--rm)

Useful for disposable containers and examples. When a container is stopped, it’s automatically removed. Handy

5/12
Publish Ports (-p)

To expose a port or a series of ports on the Host Machine.

You can also specify a protocol, for example -p 8080:80/tcp to Map TCP port 80 in the container to port 8080 in the Host

6/12
Environment Variables (-e)

Sets an environment variable in the container. It can also overwrite existing environment variables defined in the Dockerfile

7/12
Run in background (-d)

To run a container in the background, leaving the terminal free. The container ID will be printed on the terminal for further uses

8/12
Connect to a Network (--network)

Connects to a network.

To attach a running container to an existing network:
Docker network connect
To disconnect a running container from a network:
Docker network disconnect

9/12
Keep STDIN open (-i)

In some cases, a very useful option to access directly on the terminal of the container. Often used in combination with -t, to allocate a pseudo-TTY

10/12
Start a container with a volume (--mount)

Docker volumes are the preferred way to persist data in Docker.
Docker run --mount source=volume1,target=/path
Please note that even if you can use the -v option, the --mount is the new preferred one

11/12
Use a custom User (--user)

Specifies a username for the container, Very useful in some cases to avoid using the default one defined in the image

12/12

More from All

You May Also Like

And here they are...

THE WINNERS OF THE 24 HOUR STARTUP CHALLENGE

Remember, this money is just fun. If you launched a product (or even attempted a launch) - you did something worth MUCH more than $1,000.

#24hrstartup

The winners 👇

#10

Lattes For Change - Skip a latte and save a life.

https://t.co/M75RAirZzs

@frantzfries built a platform where you can see how skipping your morning latte could do for the world.

A great product for a great cause.

Congrats Chris on winning $250!


#9

Instaland - Create amazing landing pages for your followers.

https://t.co/5KkveJTAsy

A team project! @bpmct and @BaileyPumfleet built a tool for social media influencers to create simple "swipe up" landing pages for followers.

Really impressive for 24 hours. Congrats!


#8

SayHenlo - Chat without distractions

https://t.co/og0B7gmkW6

Built by @DaltonEdwards, it's a platform for combatting conversation overload. This product was also coded exclusively from an iPad 😲

Dalton is a beast. I'm so excited he placed in the top 10.


#7

CoderStory - Learn to code from developers across the globe!

https://t.co/86Ay6nF4AY

Built by @jesswallaceuk, the project is focused on highlighting the experience of developers and people learning to code.

I wish this existed when I learned to code! Congrats on $250!!
This is a pretty valiant attempt to defend the "Feminist Glaciology" article, which says conventional wisdom is wrong, and this is a solid piece of scholarship. I'll beg to differ, because I think Jeffery, here, is confusing scholarship with "saying things that seem right".


The article is, at heart, deeply weird, even essentialist. Here, for example, is the claim that proposing climate engineering is a "man" thing. Also a "man" thing: attempting to get distance from a topic, approaching it in a disinterested fashion.


Also a "man" thing—physical courage. (I guess, not quite: physical courage "co-constitutes" masculinist glaciology along with nationalism and colonialism.)


There's criticism of a New York Times article that talks about glaciology adventures, which makes a similar point.


At the heart of this chunk is the claim that glaciology excludes women because of a narrative of scientific objectivity and physical adventure. This is a strong claim! It's not enough to say, hey, sure, sounds good. Is it true?