Docker is a set of platform as a service products that uses OS-level virtualization to deliver software in packages called containers.

Installation

In most cases, you can use a shell provided by docker official to install docker on your server.

wget -qO- https://get.docker.com/ | bash

Then, you should open it and ensure the docker will be launched after login.

# for Debian & Ubuntu
systemctl start docker

# for CentOS
service docker start && systemctl enable docker.service

Image Update

To update your image you should pull the latest image from Docker Hub, destory the running container and recreate it with the new image. The data may be lost if you have not persisted them on your disk.

docker pull <DOCKER HUB COORDINATE>

docker stop <YOUR CONTAINER NAME> && docker rm <YOUR CONTAINER NAME>

docker run ...

Development

If you want to build Dockerfile by yourself and push your image to Docker Hub, I highly recommend you develop in local and push them by Github Actions which is a solution for CD/CI proposed by Github.

Building Dockerfile in local

Go to your project directory which has a file named Dockerfile first. Then you should build them.

docker build -t <YOUR DOCKER IMAGE NAME> .

You can run them in your local machine after the build process completed by docker run command like you run a docker image as usual.

Building Dockerfile with Github Actions

For more details about Github Actions, please refer to documentation of Github Actions for developer.

Each time you pushing to Github will trigger this action to build Docker image by Dockerfile in the root of project and push it to Docker Hub with latest tag. If you push to Github with a specific tag, pushing to Docker Hub will have the same tag as well.

name: Publish Docker
on: push
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/[email protected]
      - name: Publish to Registry
        uses: elgohr/[email protected]
        with:
          name: <YOUR USERNAME>/<YOUR REPO NAME>
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
          tag_names: true

Clean-up

For more details, you can see this post.

Remove all unused objects involving containers, images and networks.

docker system prune

In additional to remove all objects, you can append --volumes to the command to remove unused volumes.

docker system prune --volumes