Skip to content
On this page

Docker

Avoid using. Creates headaches and you get nothing done.

Docker CLI

Open bash inside the container

bash
docker exec -it [-u USER] <CONTAINER ID | CONTAINER NAME> /bin/bash
docker exec -it [-u USER] <CONTAINER ID | CONTAINER NAME> /bin/bash
1

Get container IP address

bash
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <CONTAINER ID | CONTAINER NAME>
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <CONTAINER ID | CONTAINER NAME>
1

Remove the old dangling images

bash
docker image prune
docker image prune
1

Docker Compose

Binding ports

yaml
services:
  app_1:
    ports:
      - <HOST PORT>:<CONTAINER PORT>
services:
  app_1:
    ports:
      - <HOST PORT>:<CONTAINER PORT>
1
2
3
4

Binding ports to host only

Bind the port to the host machine directly and it will not be exposed to the public so only the host can interact with that port. This means that container can be only accessed from localhost not from outside.

yaml
services:
  app_1:
    ports:
      - 127.0.0.1:<HOST PORT>:<CONTAINER PORT>
services:
  app_1:
    ports:
      - 127.0.0.1:<HOST PORT>:<CONTAINER PORT>
1
2
3
4

Show logs (f = follow, t = timestamps)

bash
docker-compose logs -ft [SERVICE NAME]
docker-compose logs -ft [SERVICE NAME]
1

Basic commands

bash
docker-compose [start|stop|restart]
docker-compose [start|stop|restart]
1

Build the server if configuration (or image version) has changed

bash
docker-compose up -d --build
docker-compose up -d --build
1

Updating images in docker-compose file

bash
docker-compose pull
docker-compose pull
1