Scala notes

Docker basics


List current local images

docker images

List current processes (containers, running or stopped)

docker ps -a

Stop and remove all running or stopped containers

docker ps -aq | xargs docker stop && docker ps -aq | xargs docker rm

Build image from Dockerfile from current folder, specifying a custom image tag

docker build . -t <image_tag>

Create a network

docker network create -d <network_type> --subnet x.x.x.x/mask --ip-range x.x.x.x/mask <network_name>

Example: docker network create -b bridge --subnet --ip-range net1

Running a container from an image

docker run [OPTIONS] <image_name> [COMMAND] [ARG...]

Where OPTIONS can be:

  • -i - interactive, keep stdin open even if not attached
  • -t - allocate a pseudo tty
  • -d - detach, run dontainer in background and print container id
  • -h <host_name> - container host name string
  • -p host_port:container_port - publish container's ip to host; host will forward requests to the container on the specified port; can be used multiple times
  • --network <network_name> - specify a custom network to run this container in
  • --name <custom_container_name> - assign a name to this container
  • --ip <set_ip_value> - assign a fixed ip value to the docker container


docker run -d --network net1 -p 9000:9000 --name my_image -h my_image_host my_local_image

Retrieve a running container's ip address

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}}' <container_name>

docker inspect --format '{{ .NetworkSettings.IPAddress }}' <container_name>