Docker Tip: Quick reference of commonly used docker command

// start a container with latest python
docker run 

// once container shuts down, just remove the container
docker --rm

// mount host directory to a directly inside of container
docker -v ${host_dir}:/dir_inside_container

// interactive, basically allow us to interact with something inside the container
docker -it

i.e. // start a python container and enter python interpreter
docker run \
--rm \
-it \
python:latest \
python

// -p host_port:container_port
takes host_port and forward to container_port

// -d run container in background, if not specified, it will run in foreground
start container in background if -d is specified

// if a container is issued to be run in background, we can stop it by first figuring out the container name then issue
docker stop <container name>

// check running containers, this will display container id, image, created, status, ports, and names
docker ps
docker container ls

// docker build command
docker build \
// -t is used to specify a tag for your image that you are creating
-t  python_test \
// . means build using the current directory
.

// create a container network that can be used for containers to communicate with each other
docker network create multiple

// launch container using the container network
docker --net multiple

// launch container with specific container name
docker --name specific_name

// specify environmental variable
docker -e
i.e.
docker -e ADMIN_PASS='xyz'

Comments

Popular posts from this blog

MongoDB Tips: Kill long running processes

Oracle Goldengate Extract, Pump, and Replicat

MongoDB Ops Manager Basic Installation and Configuration