Portainer.io Docker-Compose Setup

Today Portainer had an update available, so I wanted to update the image. This would not be an issue if I deployed Portainer using Docker compose. But I deployed Portainer just using Docker commands.

docker run -d -p 8000:8000 -p 9000:9000 --name=partainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest

This would need me to stop the docker container, them remove the old container before redeploying a new container just to do an update.

Step 1: 
docker ps
CONTAINER ID   IMAGE                                         COMMAND                  CREATED          STATUS                PORTS          NAMES
d3d2f4dcfa4f   portainer/portainer-ce:latest                 "/portainer"             30 days ago   Up 30 days         0.0.0.0:8000->8000/tcp, :::8000->8000/tcp, 0.0.0.0:9000->9000/tcp, :::9000->9000/tcp, 9443/tcp   portainer

Step 2:
docker stop d3d2f4dcfa4f

Step 3:
docker rm d3d2f4dcfa4f

step 4:
docker run -d -p 8000:8000 -p 9000:9000 --name=partainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest

This is not hard, but you must remember how you deployed your docker container command every time you want to update the container image.

So I took this operation to set up the Docker container as Docker compose deployment.
And these are the steps that you will have to take.

Step 1: Make a new folder to save the new docker-compose YML file.

mkdir portainer-docker

Step 2: “cd” to the new folder that you just created.

cd portainer-docker

Step 3: Using any editor you like create a new docker-compose.yml file in the directory you are in.

nano docker-compose.yml

Step 4: Copy the docker-compose sample into your editor.

version: '3.2'

services:
  portainer:
    container_name: portainer.io
    image: portainer/portainer-ce:latest
    ports:
      - "8000:8000"
      - "9000:9000"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - portainer_data:/data
    restart: always

volumes:
  portainer_data:
    external: true

Save and exit.

Step 5: Deploy your docker-compose container.

docker-compose up -d

Now doing any update is just pulling the new image and restating the container.

docker-compose pull
docker-compose down
docker-compose up -d

Leave a Reply

Your email address will not be published. Required fields are marked *