12/04/2021

Docker-2

Bazı komutlar

List running container

$ docker ps

Lists all running or not.

$ docker ps –a

Containers get random names

Lets say a docker container is running and we would like to execute a command on the running container

$ sudo docker exec mycontainer cat /etc/hosts

we must always run ın detached mode otherwise we can not use console

$ docker run –d cowsay

TAG

If we want to run another version of a software other than the latest one we do it like below

$ docker run redis:4.0

The red part is now a TAG.

To find correct tags we should check docker hub.

Port Mapping

Docker starts a internal network normally not accessible from outside. And an app in Docker uses the port there. So we need to map the ports of the docker container to hosts available port.

$docker run –p 80:5000 webapplication

So port 80 of the host will be forwarded to port 5000 of the docker container.

Inspect Container

Docker ps is good but it does not show all the details. To see all the details we need to inspect it.

$ docker inspect <CTNAME>

Environment Variables

Variables in application code you can enable receiving variables from outside as environment variables.

To send or change environment settings of docker containers we use

$ docker run –e APP_COLOR=blue simple-webapp-color

So that our Simple-webapp-color container expects to see an environment variable APP_COLOR.

And gets it as “blue”

To find the existing environment variable on a running container we use inspect.

$ docker inspect my_container

Its an output like json

“Env”: [
“APP_COLOR=blue”,
....

Leave a Reply