Linux | Docker on Linux

Introduction

Docker is a lite-weight container in operating systems. Different from VM(virtual machine), docker is good at its weight and usage. In this article, I will conclude how I install a docker in Linux Ubuntu platform. Imgur Docker will share kernal with dominate operating system, it doesn’t requires hypervisor(my understanding is adapter) between operation system and docker container.

Imgur

Docker Image

Docker image is a special file system. It will provide the environment for running a docker container, including application, library, resource and configurations. Docker is like a class, it defines the structure and its related parameters.

Docker Container

Docker container is an instance created with the definition of docker image.

Docker Repository

Docker Repository is a platform to save docker images. Its function is really like github.

Development on Docker

Imgur

Docker Installation

  1. Install docker application.
     sudo apt install docker.io
    
  2. Check docker installation
     sudo docker info
    
  3. Add current user to docker group
     sudo groupadd docker # if docker group doesn't exist, create a docker group.
     sudo gpasswd -a ${USER} docker # Add current user to docker group. 
    
  4. Run/Stop docker
    • Docker application will run as a deamon thread.
       sudo systemctl start docker
       sudo systemctl enable docker
      
    • Stop/restart docker.
       sudo systemctl stop docker
       sudo systemctl restart docker
      

Images

  1. Check existing images on current docker
     sudo docker images
    

    Imgur

  2. Pull a docker image from dockerhub, here I pulled a docker for spring cloud
     docker pull springcloudservices/spring-cloud-base
    

    Imgur

  3. Search docker images
     docker search (image keyword)
    
  4. Run one image
     # Check the name of that image
     docker ps -a
     # Create a container for a image.
     docker run -itd -p 5000:5000 (image id)
     # Enter the container
     docker attach 199c8075258c
    
  5. Exit the container
     exit
    

Dockerfile

Dockerfile is a file to customize our own docker image from another docker image. 1. FROM: It is difficult to create a docker from nothing, so FROM is way to import an existing image and customize our own image based on that. 2. RUN: Shell commands are appended to RUN. We connected all the commands with symbol &&. We want to connect all commands by && so we don’t have to create different levels. 3. ARG: ARG is the short of ARGUMENTS. 4. ENV: Set up global environment.