Skip to content

dnyk7/docker-tutorial

Repository files navigation

docker-tutorial

Some videos:

Docker Official Images

  • Has info on how to use the images
  • Includes configuration info, like environmental variables
    • That's what the -e represents

Basic Docker Commands

docker pull docker run docker start docker stop docker ps docker exec -it docker logs

docker help

  • To see all possible docker commands

docker build

  • Turns the file into an image

.dockerignore file

Excludes the files you don't want to end up in a docker image

Docker images

  • Docker Scout allows you to identify any security vulnerabilities for each layer in an image
  • It extracts the software bill of material from the image and compares it to security advisory databases
  • When there's a match, it's given a severity rating (to prioritise safety efforts)

Check the current images/ running containers

docker images

  • View the current images loaded on host machine

docker ps

  • Returns list of current RUNNING containers
  • On Docker desktop, you can click on the running container to inspect the logs, view the file system, or execute commands directly in the running container

docker ps -a

  • Returns list of running AND stopped containers

To use someone else's Docker image

  • Download it from the cloud
  • If version is not specified, it pulls the latest version

docker pull :

OR: docker run :

  • Basically 2 commands in 1: Pulls images AND starts container

eg. docker run redis:4.0

Docker Containers

To create & RUN a container

docker run: Creates new container with a command

  • Combines "docker pull" & "docker start" in one command -> Pulls image AND starts container docker run <image-name>:<version>

eg. docker run postgres:9.6

docker run -d

  • The -d creates container in a detatched mode
  • Detached mode allows you to use the terminal again? TBC

Binding container to ports (when managing multiple containers)

  • If >=2 containers are listening to the same port, ensure you bind them to different ports on your HOST machine
  • You need to create binding between container port and laptop's port for the container to be reachable by any application
  • Specify the binding of the ports during the run command
  • One laptop's port can only run one container
  • -p allows you to bind the port of the host machine to the container docker run -p<laptop's-port>:<container's-port> <image-name> docker run -p6000:6379 redis

To NAME a new container (you can't rename old ones)

docker run -d -p<host-port>:<container's-port> --name <new-container's-name> <name-of-image-you-want>
  • The -d is just to run it in detached mode (optional)

To STOP a running container

docker container stop <container-name>

OR, to forcefully stop it: docker container kill <container-name>

OR, to remove the container entirely: docker container remove <container-name>

To RESTART a container (eg. when it crashes)

docker stop <container-id>
docker start <container-id>

Debugging containers

docker logs <container-id> OR docker logs <container-name>

  • Check the logs of the container

docker exec -it <container-id> /bin/bash OR docker exec -it <container-name> /bin/bash

  • -it: interactive terminal
  • Brings you inside the container's terminal as a user

ls OR pwd

  • Check which directory you're in
  • If it is empty, to exit directory use

/

env

  • Print the environmental variables to check if things are set correctly
  • Useful if your container has a complex configuration & you want to validate that things are set up correctly
  • OR, if you're running your own application that you wrote in a container

exit

  • Exits the terminal

Docker compose (up and down)

  • For managing multi-container applications
  • Allows you to define multiple applications and their DOcker images in a single YAML config file
  • Eg. frontend, backend, and a database
  • To run all these containers simultaneously, use: docker compose up
  • To stop these running containers, use: docker compose down

docker push

  • Uploads your image into a remote registry, where it can run on a cloud (eg. AWS) with elastic container service(!!!), or it can be launched on serverless platforms (eg. Google Cloud Run)

Docker toolbox

  • Abstracts away the kernel to make it possible for your hosts to run different docker images

3 Volume types

Orchestration tools (for complex, high-traffic systems)

  • On a larger scale, orchestration tools like kubernetes (aka K8s) is needed to run and manage containers
  • A control plane exposes an API that manages the cluster, which has multiple nodes/ machines
  • Each node/machine contains a kublet & multiple pods
  • Pod: The minimum deployable unit in kubernetes, and has one/more containers inside
  • Kubernetes is effective as it automatically scales according to the desired state of the system you describe
  • Has fault tolerance to auto-heal if any server goes down

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors