Predictive Hacks

Get Started with Dockers

Docker

Docker in High-Level

Docker Images

A Docker image is an executable package that includes everything needed to run an application such as the code, a runtime, libraries, environment variables and configuration files. A container is a runtime instance of an image.

Layers of Docker Images

The Docker images are made up of layers make them to be extremely efficient and flexible. Note that the layers cannot be modified but we can build news images from existing images.

Dockerfile

The configuration file that builds that Docker image is called the Dockerfile, which is a text file that contains all the commands needed to build a docker image.

LinkedIn Learning

By convention, you should call name the Dockerfile as Dockerfile without any extension, which is a flat file. We will discuss more about the Dockerfile instructions but let’s have a look at some of them:

  • FROM : This is the first instruction and is used to define the base image
  • ADD : Copies a file into the image but supports also tar and remote URL
  • COPY : Copy files into the image, it is most common than the ADD
  • VOLUME : Creates a mount point as defined when the container is run
  • ENTRYPOINT : The executable runs when a container is running
  • EXPOSE : Documents the ports that should be published
  • CMD : Provide arguments for the entrypoint
  • ENV : Defines environmental variables in the container (usually for credentials)
  • RUN: Runs a new command in a new layer
  • WORKDIR : Sets the working directory of the container

Docker Commands Cheat Sheet

CommandsComments
docker system pruneprune the images
docker ps -aget the images
docker create busybox <container_id>create an new container, here based on busybox
docker start <container_id>start a container
docker logs <container_id>get the logs of the container
docker stop <container_id>stop a container
docker kill <container_id>kill a container
docker exec -it <container_id> <command>execute a command in an interactive terminal
docker run -it busybox shrun the shell (sh) command within busybox in an interactive terminal
docker build .build a docker image from a Dockerfile
docker run <image_id>run the docker image
docker build -t gpipis/myproject:latest .build a docker imager form a Dockerfile with a tag
docker run gpipis/myproject:latestrun the docker image
COPY <path to folder to copy from on your machine relative to build context> <place to copy stuff to inside the conainer>the COPY instruction inside Dockerfile
COPY ./ ./the COPY instruction inside Dockerfile referring to home directories
docker run -p <route incoming requests to this port on local host to>:<this port inside the container> <image id>docker run with port mapping
docker run -p 8080:8080 <docker image id or name>could be 5000:8080 and then at your browser would be localhost:5000 The second port should be consistent with your Application
WORKDIR /usr/appthis is part of the Dockerfile. Any following command will be executed relative to this path in the container. It is good to put it in the /usr but you could put it in the var or in the home
docker-compose.ymllike the Dockerfile this is the file name for the docker compose
docker-compose up –buildbuild and run the docker-compose.yml
docker-compose uprun
docker-compose up -dlaunch in backgroun
docker-compose downstop containers
docker save <image name> > myname.tarcreation of image tar file from Docker image
docker load -i myname.tarload an image from a tar file
docker export <imagename> > myname.tarcreation of image tar file from a container
docker import – <gpipis/foo> < myname.tarimport the contents from a tarball to create a filesystem image

References:

LinkedIn Learning: Docker Essential Training

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email

Leave a Comment

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore

Python

Image Captioning with HuggingFace

Image captioning with AI is a fascinating application of artificial intelligence (AI) that involves generating textual descriptions for images automatically.