Terminology:
- Image is the blueprint for building, template
- Container is the running copy of the template
Analogy: image is the cookie recipe, container is the cookie (u/Xendrak:reddit)
We will go over:
- pulling docker images
- running docker containers
- building with dockerfiles
- running home-made docker image
Verify install with the
docker
command in terminal. You should see available commandsflast
docker run hello-world
the docker image in pulled from docker hub and it is built and run
docker pull alpine
check containers on system
docker image ls
lists images on system
- the container exists on local system, but is not running.
to run
docker run --name sample-docker -it alpine
the 'it' flag is for "interactive terminal" you are now in a running docker container CONGRADULATIONS
To leave
exit
No changes to system persist
it is possible to save system changes with the
docker commit
command Example:
- make a new dir and file in a running docker image
- exit docker image
- use
docker ps -a
command to see running images docker commit [CONTAINTER ID] [new_image_name]
will make a new image with the saved changes
THIS IS NOT THE PREFERED METHOD TO SET CONTAINER. IT IS RECOMMENDED TO USE DOCKERFILES
- clone this repository into your docker-enabled system
cd
into directory where dockerfile resides
docker build -t flask-sample:latest .
- builds the docker image from the docker file.
- -t flag is to tag image (useful for versioning)
- DONT FORGET THE '.' at the end (I often miss this)
- You see the docker layers being built.
You should see
Successfully built ########
Successfully tagged flask-sample:latest
- Now the home-made docker image is ready to run.
RUN
docker run -d -p 5000:5000 flask-sample
- -d flag is detached, does not run in same terminal
- -p flag sets ports for docker and host machine
now if you go to https://localhost:5000 you should see the running flask app
YOU CAN MAKE CHANGES IN THE DOCKERFILE and FLASK APP, when you rebuild it will only make changes to layers that need changes
Docker github has some great resources to learn more