Linux | Docker on Linux
by Botao Xiao
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. Docker will share kernal with dominate operating system, it doesn’t requires hypervisor(my understanding is adapter) between operation system and docker container.
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
Docker Installation
- Install docker application.
sudo apt install docker.io
- Check docker installation
sudo docker info
- 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.
- 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
- Docker application will run as a deamon thread.
Images
- Check existing images on current docker
sudo docker images
- Pull a docker image from dockerhub, here I pulled a docker for spring cloud
docker pull springcloudservices/spring-cloud-base
- Search docker images
docker search (image keyword)
- 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
- 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.
Subscribe via RSS