Skip to main content

Docker

Images

docker images

Containers

docker container ps
-a stopped containers

Run

docker run <image_id>|<image_repo_name>
-d daemon/detach
-p publish/expose local_port:remote_port
--name <name> alias

Stop

docker stop $(docker ps -a -q)

Start

docker start <container_id>

Shell

docker exec -it <container_id> bash

Memory/CPU

docker stats

Network

docker network create example
docker run -d --net example --name container1 <image>
docker run -d --net example --name container2 <image>

Run host apps within container

Attach host executable to a running container's network namespace:

  1. Get the pid ps -ef | grep gafana
  2. sudo nsenter --target [PID] --net /usr/sbin/tcpdump
  3. As a sidecar: docker run -it --net container:nginxtest raesene/alpine-containertools /bin/ash

Credits

Ubuntu + Docker (Firewall)

sudo ufw allow from 172.0.0.0/8

Credits

Access Host from container

Ubuntu

Use 172.17.0.1

Mac?

Use host.docker.internal