DEV Community

Cover image for NEED TO KNOW ABOUT DOCKER
Emmanuel Essien
Emmanuel Essien

Posted on

NEED TO KNOW ABOUT DOCKER

Docker is a platform designed to help developers build, share, and run applications using containers. Docker itself is not a platform as a service; rather, it is a containerized platform.

CONTAINERS
Containers are lightweight, portable units that bundle an application with all its dependencies ensuring it runs consistently across different environment.

BASIC DOCKER CONCEPTS

  1. CONTAINERS: Containers are isolated environments that package your application and its dependencies. They are like lightweight virtual machines but share the host system kernel, making them faster and less resource-intensive

  2. IMAGES: A docker image is a lightweight, standalone, and executable software package that includes everything needed to run an application.

  3. Docker Engine:
    This is the core of Docker that allows you to build, run, and manage containers.

  4. Docker File:
    A text file with a set of instructions for building a Docker image. For example, it defines the base image, application code, dependencies, and any configuration needed.

  5. Docker Hub:
    A cloud-based repository where you can find and share Docker images. It’s like GitHub but for container images.

BASIC DOCKER COMMANDS

  1. FROM:
    Defines a base image, it can be pulled from Docker Hub.
    (For example, if we want to create a JavaScript application with Node.js as the backend, then we need to have Node as a base image so it can run the Node application.)

  2. RUN:
    Executes a command in a new image layer (we can have multiple RUN commands).

  3. CMD:
    Command to be executed when running a container.
    (It is advised to have only one CMD command. If a Dockerfile has multiple CMDs, it only applies the instructions from the last one.)

  4. EXPOSE:
    Documents which ports are exposed.
    (It is only used for documentation.)

  5. ENV:
    Sets environment variables inside the image.

  6. COPY:
    Used to copy your local files/directories to the Docker container.

  7. ADD:
    It is a more feature-rich version of the COPY instruction.
    • COPY is preferred over ADD.
    • The major difference between ADD and COPY is that ADD allows you to copy from a URL as the source, while COPY can only have local ones.

RUNNING DOCKER ON UBUNTU

  • STEP 1: U need to install docker engine on ubuntu on your VM-Ware Workstation. Open your browser on your VMWare Virtual Machine https://docs.docker.com/engine/install/ubuntu/ scroll till INSTALL USING DOCKER APT REPOSITORY copy the code. Head to terminal on your VMWare Environment make sure you are in root directory using the command sudo su then paste it in your VM Ware workstation

More info

More info

Copy the second code from the website and paste

More info

More info

  • STEP 2: To Verify that we have successfully installed docker we paste the third code in our environment if it shows HELLO WORLD it means docker has been successfully be installed.

HELLO

HELLO WORLD

RUNNING NGNIX USING A CONTAINER

  • We head to a docker hub. We are going to generate a container image.

container image

Search for ngnix

NGNIX

  • We need to pull the image.to do this we use the command docker pull nginx This will pull it the image from a repository and download it in our local environment.

docker pull

  • After downloading the command we need to run the container images. We run the command docker run --detach --all nginx:latest the dash (-d) will run docker in the background.

NGNIX

  • We run the command docker ps to get the port. This command will give us all the information about the running command.

docker ps

  • Another step is to get the IP address we run the command ip addr show

Ip addr show

Notice the IP ADDRESS from number 2 in the terminal we have to copy it and paste it our browser add column (:) the port number also, as shown below

IP ADDRESS

This confirms that we have successfully installed the NGINX on the system.

  • Next we create a directory mkdir (name of directory) and enter into it using CD(name of directory)

More info

  • To build a docker file we first need to create a text document. First a text editor need to be installed using the command apt install vim

More info

  • Then we create a text document using vim dockerfile code which will automatically take us to the text editor page as shown below:

More info

TEXT FILE

  • Every dockerfile need a parent the first command. The left hand side commands, will be instructions while the right handside will be the name of the parent is. For example from (name of the parent) the first command FROM is the instructions followed by the parent. To exit the text editor we enter escape shift column wq

More info

  • Next we build the app we created in the text editor using command docker build -t (name of app) .

Build docker

Docker has revolutionized the way developers build, deploy, and manage applications. Its containerization technology enables consistent environments, resource efficiency, and rapid scalability, making it an essential tool in modern software development and DevOps practices. By reducing dependencies and simplifying deployment processes, Docker bridges the gap between development and production environments.

As organizations continue to adopt cloud-native architectures, understanding Docker and its ecosystem is no longer optional but a necessity for staying competitive in today’s tech-driven landscape. Whether you’re a seasoned developer or a beginner, embracing Docker will undoubtedly enhance your ability to deliver reliable and scalable software solutions.

Dive into Docker, experiment with its capabilities, and unlock its full potential to elevate your development workflow!

Top comments (0)