Training - Docker
Last Updated on: August 17, 2021 pm
Training - Docker
Log in to Linux Server
- Turn on the personal linux server on https://student.conygre.com/
- Open a terminal and do
ssh grads@devopsnama23.conygre.com
- Password:
c0nygre
- run
docker run -d -p 8081:8080 nicktodd40/compactdiscs
- to launch a docker container - Go to a browser - type in
devopsnama23.conygre.com:8081
Docker Overview
Docker containers abstract some of the Linux OS capabilities and the virtualization is done at the OS layer.
Docker Abstraction
Docker containers run in separate namespaces sharing the kernel of the host OS.
- Makes the containers much faster to launch than a VM
- Means that containers on the same host are NOT totally isolated – more on that later
Run Docker
docker --version
check if installed.
DockerHub
Images are commonly used from DockerHub Repository.
Launch a Container
docker run tomcat:9
Run a container from the Tomcat9 image from the dockerHub.
More useful option:
docker run –d –p 8081:8080 tomcat:9.0
-d Flag
To put the container in the background, use the –d
flag
Port Binding
The -p
flag allows you to bind ports between Docker Host and the container port.
In the example above:
Port 8081 on the Docker Host is now going to forward to the Container port 8080
What is running?
docker ps -a
- show all the running docker containers
Starting & Stopping Containers
docker stop [id]
docker start [id]
The [id] is the first couple of char from the Container ID.
Destroy Containers
docker rm -f [id]
Docker Images
- Docker images are the template from which we launch container
- Each image is based on a parent image
- Each image therefore consists of multiple layers
- Each layer contains directories and files
Building the Image
docker build -t trades .
-t
- you can can provide a tag for the image
- To enable easy identification
- In order to push to a repository (more on that later)
.
- The period (.) is the directory containing the Dockerfile
Dockerfile
1 |
|
FROM
- specifies the base image, this base image will be copied down from Artifactory onto your local machineADD
- Files to copy into the image from the local machineEXPOSE
- specify which port to expose to the outside worldRUN
- Command to run at buildWORKDIR
- Working directories for subsequent commandsENV
- Environment VariablesCMD
- used when you might want to override the command that is used when you launch the container - like["npm", "start"]
ENTRYPOINT
- used for images that are running server software where you are unlikely to want to override what it is doing
Manage Images
docker images
Remove Images
docker rmi [imageName]
Sharing Images
docker login
docker push
docker pull
Appendix
Pull Jenkins Server
docker run -p 8081:8080 jenkins/jenkins:lts-jdk11
Then open devopsnama23.conygre.com:8081
to open Jenkins in docker container - because of pulled image
devopsnama23.conygre.com:8080
also a Jenkins running - directly on the Linux server.