Docker miscellaneous commands (cheatsheet)

September 25th, 2020

This command lists out the local images stored on your docker server

docker images

This command searches the docker repository.  Note that the highest rated (starred) images are listed at the top

docker search <search text>

This command will pull the image from the docker repository to your docker server

docker pull <image name>

This command will remove a docker image

docker rmi <image name>

This command will show *all* docker containers (running or not)

docker ps -a

This command will remove a docker container

docker rm <container name>

This command will display a ton of information about a container - including the IP address

docker inspect <container name>
docker inspect <container name> | grep IP

This will start up a docker container with port mapping - the host port will be chosen randomly

docker run -d -p 8080 <image name>

This will start up a docker container with directory mapping

docker run -d -v /path/on/host:/path/in/container

This will start up a docker container with port forwarding - the port will be assigned

docker run -d -p <host port>:<docker port> <image name>
docker run -d -p 8000:8080 <image name>
docker run -d -p 8000:8080 -p 8001:8080 <image name>

This will start up a docker container in host mode (use the ip address of the host and open the ports from the container on the host directly)

docker run -d --net=host <image name>

This will start up a docker container and specify the container name

docker run -d --name <container name>

There are multiple ways to connect to the container.  Attach is not recommended as it relies on the container actually running a shell.

docker attach
docker exec -i -t <container name> bash

You can attach to containers, make changes and create a new image by using the commit command (recommend to prefix the image with "my" or initials)

docker commit <current container name> <new image name>

This will build a docker image from a Dockerfile in the current directory

docker build -t <image name> .

 

Docker example of creating simple dockerized app

September 25th, 2020

Here is a very simple example of how to create a dockerized app:

docker run -d centos /bin/bash -c 'while true; do X=$[$X+1]; echo $X; sleep 1; done'

To check if it is running:

docker ps

To check the output, use the auto-assigned name or (unique) portion of the container id

docker logs auto-name

To stop:

docker stop name

To start

docker start name

 

Installing Docker

September 25th, 2020

The easiest way to install Docker (on linux) is to use the following

curl -fsSL https://get.docker.com -o get-docker.sh
chmod 755 get-docker.sh
./get-docker.sh

 

How to start a shell in a Docker container

September 3rd, 2020

To list the docker processes and get the container id:
docker ps

Then use:
docker exec -it <containerIdOrName> bash

How to get bash or ssh into a running container in background mode?

How to have an app run on Startup in Windows 10

September 3rd, 2020

Press Windows+R to bring up the Run menu
Type "shell:startup" and hit enter
Create a shortcut in that folder to the program you want to run on startup