DEV Community

loading...

Docker 101 - What it is and how to start using

luturol profile image Rafael Ahrons Updated on ・2 min read

You can see the original post in my personal blog

What is Docker?

Docker is a tool which controls containers and makes it possible for developers to use container with their own applications.

Putting on a container, you have the advantage to grant that your application will always run fine and with the same environment every time, cause it is configurated in a container with all needed specifications.

Docker has it's own interface standardized for all operations.

Has it's own container orchestration.

What is a container?

It's something that packages up all application dependencies and code so the application runs as fine as it can. You can read more at What is a Container? from docker page

Running a container

docker container run -t ubuntu top

docker container run initialize a container.

-t add an pseudo-TTY to the image.

run first execute a docker pull to get ubuntu image for the host. After downloaded, initialize the container with the Ubuntu image.

top is a Linux command that shows all active process order by memory consumption.

Looking at the output on bash you gonna see only the root process running, which means that all container is isolated from which other, avoiding conflicts between one and another.

Even using the same image from Ubuntu, it's important to note that the container does not have it's own kernel. It uses the host kernel and the image is used only to provide the file system and tools available on Ubuntu.

Get inside the container

docker container exec -it

Allows you to enter the container terminal.

-it allows you to enter without executing any command and you can navigate on it.

Show all containers

docker container ls

Shows all the containers that are running.

Using container ID to get into it's terminal

docker container ls
--Get the container ID
docker container exec -it CONTAINER_ID bash

--to leave from the container
exit

The last argument selects the terminal to use. You can see on Docker hub which terminal is available to use.

Stopping a container

docker container stop container_id

You can use only the first 3 digits in the container ID to identify the contaier, those digits is whats make a container unique.

It's possible to stop more than one container at once:

docker container stop d67 ead af5

Removing a container

docker system prune

Remove all stopped containers.

Thanks for reading it. I've been using docker for a while now and it's amazing having all my projects running without conflict and even their on database. I'm tired to install and configure all different types of databases...

Don't forget to drink water and eat clean.

Discussion

pic
Editor guide