Ubuntu system installation Docker

There are several ways to install Docker CE, the following is the easiest method by installing Docker warehouse, other method, see the official documentation .

Setting warehouse

  1. Refresh Package

    sudo apt-get update
  2. Install the necessary software packages

    sudo apt-get install \
        apt-transport-https \
        ca-certificates \
        curl \
        gnupg-agent \
        software-properties-common
  3. Add Docker official GPG key

    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

    Verify whether the fingerprint 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88can be verified by 8 after a search of the fingerprint.

    sudo apt-key fingerprint 0EBFCD88
    
    result:
     pub   rsa4096 2017-02-22 [SCEA]
           9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
     uid           [ unknown] Docker Release (CE deb) <[email protected]>
     sub   rsa4096 2017-02-22 [S]
  4. Use the following command to add stable version warehouse

     sudo add-apt-repository \
           "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
           $(lsb_release -cs) \
           stable"

Installation Docker CE

  1. Refresh Package

    sudo apt-get update
  2. Install the latest version of the docker ce and containerd

    sudo apt-get install docker-ce docker-ce-cli containerd.io
  3. By running hello-worlda mirror to verify that the installation was successful

    sudo docker run hello-world

    Docker CE after the installation is complete, will create dockera user group, but no user is assigned, so the need sudoto run Docker command.

other settings

Mirror accelerate domestic container

Use accelerator can improve the speed of image acquisition Docker official, use the following Ali cloud mirror accelerated.

By modifying the daemon configuration file /etc/docker/daemon.jsonto use accelerator

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://jjzi6741.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

Use non-root user management to run Docker

Reference links

Docker daemons bound Unix socket rather than a TCP port. By default Unix socket attributable to the rootuser, other users can only sudoaccess the command. So Docker daemon always rootuser to run.

If you do not want to run every dockercommand in front with sudo, you can create a dockeruser group and the user added. When Docker daemon starts, it will create a Unix socket for dockeruser group members to access.

caveat

dockerUser group members and rootusers have the same privileges, see Docker Daemon Attack Surface to learn more about the impact of system security.

Create a dockeruser group and add your user

  1. Creating dockeruser groups

    sudo groupadd docker
  2. Add your user to dockeruser group

    sudo usermod -aG docker $USER
  3. Permission to re-sign in to try to take effect.

  4. Verify that you can not use the sudocommand to rundocker

    docker run hello-world

    This command will download and run a test image in the container. After the run is completed, it will display a welcome message and exit.

    If you are added to the user dockerusing a user group before sudorun-off Docker command, you may encounter the following error message, because ~/.docker/permissions are not caused.

    WARNING: Error loading config file: /home/user/.docker/config.json -
    stat /home/user/.docker/config.json: permission denied

    To solve this problem, you can delete ~/.docker/(custom settings will be lost) directory, or use the following command to change permissions.

    sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
    sudo chmod g+rwx "$HOME/.docker" -R

Installation Docker Compose

Reference links

In the Linux system, you can Compose repository release page on GitHub to download Docker Compose binaries.

For the alpinesystem, install the following dependencies: py-pip, python-dev, libffi-dev, openssl-dev, gcc,libc-dev make

  1. Run the following command to download the latest stable version Docker Compose

    sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

    Download different versions, you can change the version number of the command.

  2. To file with executable permissions

    sudo chmod +x /usr/local/bin/docker-compose

Note : If you perform the installation docker-composefails, check the PATHvariables. Also soft link can be established.

such as:

sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
  1. (Optional), to bashand zshmounted Command Completion .

  2. Verifying Successful Installation

    $ docker-compose --version
    docker-compose version 1.24.0, build 1110ad01

Guess you like

Origin www.cnblogs.com/codingbit/p/install-docker-in-ubuntu.html
Recommended