With docker installed, here are some common commands you will use. I have also provided some example code to check out.
docker ps
example output
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
17f6f866d38c 446dbae429b7 "docker-entrypoint.s…" 6 minutes ago Up 6 minutes 0.0.0.0:8000->4000/tcp festive_knuth
Breakdown
docker build -t [username]/[appname:version] [directory]
Example
docker build -t daltonhj/docker_example:1.0 . # the . here is current directory
The run command actually builds the container and then starts it up.
Breakdown
docker run -d -p [local port]:[container port] [imageID]
Example
docker run -d --name myContainer -p 4000:4000 446dbae429b7
Breakdown
docker stop [container]
Example
docker stop myContainer
Breakdown
docker start [container]
Example
docker start myContainer
docker volumn create [volumn name]
Example
docker volumn create shared-stuff
docker run -d --name myContainer --mount source=shared-stuff,target=/stuff -p 4000:4000 446dbae429b7
Breakdown
docker exec [container name] [command to run]
Example
docker exec myContainer cat src/index.js
Want to access the bash terminal inside the container?
docker exec -it myContainer /bin/bash
If you setup a docker-compose yaml file this will make things a lot easier as you will not need to run the above commands and allows you to define the commands for multiple containers in the same go.
With yaml file created to start up
docker-compose up -d
To spin up multiple containers per image
docker-compose up --scale [service]=[amount]
With yaml file to spin down
docker-compose down