A Cheatsheet for cognitiveclass.ai course
1. Run a container
Note: this is a fairly old course, from now on I will update the commands used. For the labs part of this course you can either install docker on your machine or use the Docker Playground.
docker run -t ubuntu top
List em (old but still useful, better use docker ps)
docker container ls
From other node:
docker exec -it b3ad2a23fab3 bash
or
docker exec -it b3a bash
List the running processes
ps -ef
2. Run multiple containers
A simple container
docker run -d -p 8080:80 --name mynginx nginx
Check it on http://localhost:8080
Now a mongo container
docker run -d -p 8081:27017 --name mongo mongo
List ’em (check their size)
docker ps -s
Stop a container (three digits is enough)
docker stop <container_id>
Remove all stopped containers, networks, dangling images and build cache.
docker system prune
Check images in your computer
docker images
Re check containers
docker ps
The solution for the first test is available here.
3 Docker images: Create and build a Docker image.
Create the Dockerfile
FROM python:latest RUN pip install flask CMD ["python", "app.py"] COPY app.py /app.py
Build the image
docker build -t python-hello-world .
Check our image
docker images
Run a container of this image
docker run -d -p 5001:5000 python-hello-world
Run the app (created in app.py) from the browser
http://localhost:5001/
Or using CURL from the terminal
CURL http://localhost:5001/
Check the container log
docker logs <container_id>
Push the image to Docker hub.
First, login to docker from the console
docker login
Then tag your image
docker tag python-hello-world:latest martincx/python-hello-world
Push the image to the Hub
docker push martincx/python-hello-world
Deploy a change
Just change the code of the app and then rebuild the image with the same build command just adding the hub username
docker build -t martincx/python-hello-world .
Push the changes to the hub
docker push martincx/python-hello-world
Check image history
docker image history martincx/python-hello-world:latest
Remove containers
First stop the running container
docker stop 087
Then, remove it
docker system prune