Why Docker?

Docker is a tool for running application in an isolated environment.

Some reasons you might want to use Docker:

  • Same environment: Same environment in developers machines and production servers. Acts the same.
  • Sandbox projects: Eliminates the risk of getting conflicts while working on different projects on same machine.
  • Easy working without setup hassle: Start working directly on others projects without setting all of the environments.
  • Debug your app, not your environment: Securely build and share any application, anywhere.

Container, Image, Dockerfile, Docker Hub:

Container is a running instance of an image. An image is a template for creating the environment you want to snapshot out of a system at a particular time. An image includes:

  • Operating system
  • Software
  • Application Code

Images are defined by a Dockerfile. Dockerfile is a text file with the steps to perform to create that image. It includes the following ordered instructions:

  • Configure the operating system
  • Install the necessary software
  • Copy the project file in right places

Building the Dockerfile will create the image which is run in the container.

Docker Hub: The world’s leading service for finding and sharing container images with your team and the Docker community.

Environment

  • Operating System : Ubuntu 22.10 (64-bit)
  • Processor : 12th Gen Intel® Core™ i9-12900HK × 20
  • Memory : 16.0 GiB

Docker Installation Procedure in Ubuntu 22.10

The following steps showed the step by step installation guideline. This instructions shows the way of installing Docker using the Docker repository.

Set up the repository

  1. Update the apt package index:

    sudo apt-get update
    
  2. Uninstall old versions: Older versions of Docker were called docker, docker.io, or docker-engine. If these are installed, uninstall them:

    sudo apt-get remove docker docker-engine docker.io containerd runc
    
  3. Install packages to allow apt to use a repository over HTTPS:

    sudo apt install apt-transport-https ca-certificates curl software-properties-common
    
  4. Add Docker’s official GPG key: GPG is the GNU PGP encryption program. PGP is an identification key system people use to sign files or emails so the receiver can check the authenticity of them.

    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    
  5. Set up the stable repository. The following command is for x86_64 and amd64 architecture.

    sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
    apt-cache policy docker-ce
    

Install Docker Community Edition (CE)

  1. Update the apt package index:

    sudo apt-get update
    
  2. Install the latest version of Docker Engine - Community:

    sudo apt install docker-ce
    sudo systemctl status docker
    
  3. Verify that Docker CE is installed correctly by running the hello-world image:

    sudo docker run hello-world
    

    It downloads a a test image and runs it in a container. When the container runs, it prints informational messages and exits.

    Hello from Docker!
    This message shows that your installation appears to be working correctly.
    
    To generate this message, Docker took the following steps:
    1. The Docker client contacted the Docker daemon.
    2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
    3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
    4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.
    
    To try something more ambitious, you can run an Ubuntu container with:
    $ docker run -it ubuntu bash
    
    Share images, automate workflows, and more with a free Docker ID:
    https://hub.docker.com/
    
    For more examples and ideas, visit:
    https://docs.docker.com/get-started/
    

Post-installation steps for Linux

This section contains optional procedures for configuring Linux hosts to work better with Docker.

Manage Docker as a non-root user

The docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root and other users can only access it using sudo. The docker daemon always runs as the root user.

If you don’t want to use sudo when you use the docker command, create a Unix group called docker and add users to it. When the docker daemon starts, it makes the ownership of the Unix socket read/writable by the docker group.

Warning: The docker group grants privileges equivalent to the root user.
  • Create the docker group:

    sudo groupadd docker
    

    You may get that docker group already exists:

    groupadd: group 'docker' already exists
    
  • Add your user to the docker group:

    sudo usermod -aG docker $USER
    
  • Log out and log back in so that your group membership is re-evaluated.

  • Activate the changes to groups:

    newgrp docker
    
  • Verify that the current user is added to docker group:

    getent group docker
    
  • Verify that you can run docker commands without sudo.

    docker run hello-world
    

    This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.

(Optional) Run Docker Ubuntu Image

docker run -it ubuntu

References

Advertisement

Citation

Click to select citation style

Shovon, A. R. (2020, March 10). Install Docker on Ubuntu 22.10. Ahmedur Rahman Shovon. Retrieved December 3, 2024, from https://arshovon.com/blog/install-docker-on-ubuntu-22-10/

Shovon, Ahmedur Rahman. “Install Docker on Ubuntu 22.10.” Ahmedur Rahman Shovon, 10 Mar. 2020. Web. 3 Dec. 2024. https://arshovon.com/blog/install-docker-on-ubuntu-22-10/.

@misc{ shovon_2020,
    author = "Shovon, Ahmedur Rahman",
    title = "Install Docker on Ubuntu 22.10",
    year = "2020",
    url = "https://arshovon.com/blog/install-docker-on-ubuntu-22-10/",
    note = "[Online; accessed 3-December-2024]"
}
Related contents in this website
Install Docker on Ubuntu 22.10