-
Notifications
You must be signed in to change notification settings - Fork 126
Docker Basic Commands Example
Some basic commands include
# To list running containers
docker ps
# To list containers both started / stopped
docker ps --all
# To start a container
docker start [containerid]
To use docker as a non root user
usermod -aG docker username
To debug or view what's going on within the docker server daemon
docker events
In this example we're going to setup a couple of ubuntu images called test1 and test2.
For the network I've specified defnet.
In some cases with images that don't run an actual service such as debian, ubuntu or busybox
we need to add in a -it command line option.
The -t allocates a pseudo-TTY which stops the container from going into a start / stop loop since it has no service to run otherwise.
The -i specifies it should be interactive, this means we can attach to it to run some commands from the outside.
docker run -it -d --name=test1 --restart=always --network=defnet ubuntu:latest
docker run -it -d --name=test2 --restart=always --network=defnet ubuntu:latest
Now we can attach to the test1 container (this can also be done within portainer's web gui)
# This lists the running docker containers
docker ps
# Attach to container test1
docker attach test1
Within the new ubuntu shell we can now install some network tools for ping / testing.
apt update
apt install iputils-ping
apt install net-tools
apt install dnsutils
Lets try some network access
# Show which ip address we're on
ifconfig
# Try pinging the outside - google's dns server
ping 8.8.8.8
# Try pinging the container test2
ping test2
You'll notice with user defined networks (not the default bridge one) one docker container can resolve another one by it's container name instead of having to rely on ip address's
Wiki content license: Creative Commons Attribution-ShareAlike 4.0 International License