DevOps Classroom Series – 20/Aug/2021

Containers

  • We will try to cover the following

    • Running the first container
    • Starting, Stopping and Removing Containers
    • Inspecting Containers
    • Exec into running container
    • Attaching to a running container
    • Retrieving container logs
    • Port Forwarding
  • To Get used to commandline use --help or cheatsheets

  • Docker version command if everything works correctly will show the client and the server versions installed Preview

  • Lets try to run a first container hello-world

docker container run <docker-image>

docker container run hello-world

Preview

  • Lets try to pull the image and view the sizes of the images
docker pull <image>

Preview

  • Lets try to create a container
docker container run alpine
  • Now lets look at the containers running on the system
docker container ls
  • Now lets look all the container irrespective of their current state
docker container ls -a

Preview

  • For every container created docker will create
    • container id
    • container name if not passed
  • So lets to create a container from some image with a name
docker container run --name <name> <docker-image>

Preview

  • Lets disect the command which we are passing Preview
  • Three basic linux commands which finish immedietly, after 10 seconds, till user quits (ctrl+c) Preview
  • Now lets try to run these commands as process inside the alpine container Preview
  • By default when we run docker container, it attaches the standard output to the terminal where we execute commands Preview
  • We can specify the docker to run in background mode(detached mode)
docker container run -d <image-name>
  • The containers lifetime depends on how long the command or process that gets started when container is created is running Preview
  • All of the docker images have some command that gets executed when the container is created & in many cases (httpd, nginx etc) these are good enough as the they start the application and the command execution doesn’t stop as long as application in contianer is running, so as long as app in container is running container will also be in running state.
  • How to remove containers
docker container rm <container id or name> # this is for the stopped or exited

docker container rm -f <container id or name> # this works for container in running as well as stopped

Preview

  • if you want to remove all the running containers
docker container rm -f $(docker container ls -q)

Preview

  • IF you want to remove all the containers
docker container rm -f $(docker container ls -a -q)

Preview

  • Now lets create a httpd container Preview
  • We can start the container and stop the container
docker container start <container id or name>
docker container stop <container id or name>

Preview *

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Floating Social Media Icons by Acurax Wordpress Designers

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube