What is Docker?
What is a Dockerfile?
What is a Docker container?
What is a Docker image?
Check if Docker is installed on local machine:
docker
To check the docker version, run
docker version
It will give the following output
Client:
Cloud integration: v1.0.35+desktop.5
Version: 24.0.7
API version: 1.43
Go version: go1.20.10
Git commit: afdd53b
Built: Thu Oct 26 09:08:44 2023
OS/Arch: windows/amd64
Context: default
Server: Docker Desktop 4.26.1 (131620)
Engine:
Version: 24.0.7
API version: 1.43 (minimum version 1.12)
Go version: go1.20.10
Git commit: 311b9ff
Built: Thu Oct 26 09:08:02 2023
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.25
GitCommit: d8f198a4ed8892c764191ef7b3b06d8a2eeb5c7f
runc:
Version: 1.1.10
GitCommit: v1.1.10-0-g18a0cb0
docker-init:
Version: 0.19.0
GitCommit: de40ad0
docker pull> downloads an image from the Docker Registry.docker run> runs a container from an image. This commands does 2 things at once; - downloads an image from the Registry - then runs a container from the image.docker run -p 8081:80 -d imagename> runs a container from an image and maps the container port to 8081 on a detached mode i.e the container will continue running in the background.docker port containerID> shows the port that the container is mapped to.docker ps> shows all running containers.docker ps -a> shows all containers; both running and stopped.docker images> shows all images available locally on our docker host.
RUN is for defining the commands that have to run during the build process to create an image and CMD is to define which command should be executed when you finally start the container from the existing image
A Dockerfile that displays a web page Deploying a static website as a container
- create a directory - shecodeafrica
- Change into the directory
- create a html file using the VIM editor displaying the message "Welcome to SCA Cloud School Application"
- Create a Dockerfile showing: from the NGINX server (choosethe smallest, i chose alpine) copy from the static directory where the static files are stored
- Build the docker image
- View that the docker image has been created, and you can filter through the command : sudo docker images ¦ grep shecodeafrica
- Run the docker image and name the container in the command (-d flag is to run the daemon in the backround, --name to name the container) sudo docker run -d --name shecodeafricaapp-container -p 80:80 shecodeafrica-app:v1
- View the running processes using sudo docker ps
- viewing on localshost shows the message "Welcome to SCA Cloud School Application"
- View logs using :