Docker is a tool for creating environments. For example, if we need to test something on a clean linux we could use docker to test it instead of virtual machine. That is what I am going to do here.

Create and start docker container

In order to create and run docker container we first need to pull docker image:

docker pull <image_name>

We are going to assume we pulled alpine Linux image from now on. Now we can write:

docker run alpine <command>

NOTE: use sudo if we get a permission error.

With the above command we can only run one command in our docker container before it exits. In order to change that we can run a container in interactive mode. We do it the following way:

docker run -it alpine

Notice that we left out <command> and added -it option which tells docker to go into interactive mode. If we didn’t leave out <command> then above docker run command would behave like we left out -it option. Interactive mode gives us a terminal into newly run container. In this mode we can type in commands in real time into container and see how our system behaves.

Finally if we don’t want to keep all these newly run containers we can add one more option to our run command:

docker run -it --rm alpine

Leave a Reply