Docker Reference / bert: 18:31 05/01/2020 / Category: Code  

MGMT high level

sudo docker images - show images
sudo docker ps -a - show all runs
sudo docker ps -l - show last
sudo docker commit 2f3a33f67426 - commit by ID
sudo docker commit image_name new_image - Create new image from existing image
sudo docker tag a2499a7c797b0a4f108283096523c9ea9af5dc6e618415f1513bd1d54097cccd new_image_name - Set tag for image/Give image name rather than hash
sudo docker run --name berts_new_docker -d ubuntu bash -c "cat /etc/password" - makes new docker from existing image and gives it a name, runs cmd

MGMT running containers

sudo docker attach docker_name_or_id - Jump into container that is running in the background (ran with -d)
ctr + p ctr + q - jumps out, leaves running
sudo docker exec -ti running_image_name bash - Runs bash in images
sudo docker kill container_name - Stops it (Stopped containers still exist)
sudo docker rm container_name - Removes it

Flags to use

--rm //Removes container after its done its thing
-ti //Terminal Interface (Decent shell interface)
-d //Detached (runs in background)
-p //Port ('docker port container_name' shows ports open)
-p/udp //Set protocol
--link //Adds container name to the host file


1. sudo docker run --rm -ti -p 1337:1337 -p 2600:2600 --name ech_test_server ubuntu:14.04 bash

** PORT Outside of container -> 1337:1337 <- Inside of container
** If you dont set the outside port it will be assigned dynamicaly

Example... In this new container run net cat to pipe input through ports

2. In container: nc -lp 1337 | nc -lp 2600
Then on host -
3. In one terminal "nc localhost 1337"
4. In second terminal "nc localhost 2600"
5. Now input into first terminal will output in second terminal.

sudo docker run --rm -ti --link local_docker_image_to_link --name this_client ubuntu bash


sudo docker logs berts_new_docker - View logs from a container
sudo docker run --memory maximum-allowed-memory image_name - Sets max memory