How to install docker and portainer on ubuntu (Complete Guide)

I used to run docker container with GUI environment which is with Portainer. Portainer is easy to use and it's web based, so that we can access it thought web browser and any time we can login and install our container with portainer stack and docker compose also we can use pre configured templates.

If you're planning to manage containers easily, Docker combined with Portainer is one of the best setups you can have. In this post, I’ll guide you step-by-step on how to clean up old Docker installations, install the latest Docker version, and deploy Portainer to manage everything visually.

Let's move in!

Step 1: Remove Old Versions of Docker

If you already have a pre-installed Docker version, it's a good idea to remove the old packages first. Run the following command to clean up:

  • for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done
    • this command will not delete and files and folders related to docker
  • sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras
    • this will remove all the packages related to docker

This ensures no old or conflicting Docker packages interfere with the fresh installation.

Step 2: Set Up the Official Docker Repository:

  • sudo apt-get update
    • update your system and install necessary dependencies
  • sudo apt-get install ca-certificates curl
  • sudo install -m 0755 -d /etc/apt/keyrings
  • sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
  • sudo chmod a+r /etc/apt/keyrings/docker.asc
    • add Docker’s official GPG key
  • ARCH=$(dpkg --print-architecture); CODENAME=$(source /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}"); echo "deb [arch=${ARCH} signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu ${CODENAME} stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null; sudo apt-get update
    • add the docker repository

Step 3: Install Docker Engine and Docker Compose

  • sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
    • now, install Docker and its related components, type y to continue
  • docker --version
    • to verify the installation, check the Docker version

You should see the Docker version displayed, confirming the installation was successful.


Step 4: Deploy Portainer for Easy Container Management

Portainer provides a web UI to easily manage Docker containers, images, volumes, and networks.

  • docker volume create portainer_data
    • create a Docker volume for Portainer
  • docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:lts
    • run Portainer as a Docker container

This command will start Portainer and bind it to ports 8000 (for internal communication) and 9443 (for accessing the web UI via HTTPS).

  • https://localhost:9443/ 
    • access Portainer - I am using my local server IP - https://192.168.1.176:9443
    • open your web browser and visit the address and set your 12 digits admin password

Follow the setup wizard to create your admin user and start managing your Docker environment easily!

Comments