This page looks best with JavaScript enabled

Running docker on raspberry pi

 ·   ·  ☕ 5 min read

    Install docker on raspberry pi

    curl -sSL https://get.docker.com | sh
    

    Add non-root user to docker group

    $ sudo usermod -aG docker $USER

    Install Docker Compose

    sudo pip3 -v install docker-compose

    Start docker on boot

    $ sudo systemctl enable docker.service
    $ sudo systemctl enable containerd.service
    

    To disable this behavior, use disable instead.

    $ sudo systemctl disable docker.service
    $ sudo systemctl disable containerd.service
    

    Pull Image

    docker pull hello-world
    

    Run image

    docker run hello-world
    
    docker exec -it CONTAINER_NAME sh
    # Now you can enter command in the container
    

    List containers

    docker ps
    

    List image

    docker image ls 
    # List all available images in your machine.
    docker image ls -aq
    # list image ids only
    

    Build Image

    docker image build -t IMAGE_NAME:BUILD_NUMBER .
    # build image based on docker file in Current directory (.)
    

    Stopping container

    docker stop CONTAINER_ID 
    # copy container id from docker ps
    docker stop $(docker ps -aq)
    # stop all Running containers
    

    Remove container

    docker rm CONTAINER_ID
    # Delete Specific container
    docker rm $(docker ps -aq)
    # Remove all container
    

    Restart policy

    –restart

    no  
    Do not automatically restart the container. (the default)
    
    on-failure 	
    Restart the container if it exits due to an error, which manifests as a non-zero exit code.
    
    always 	
    Always restart the container if it stops. If it is manually stopped, it is restarted only when Docker daemon restarts or the container itself is manually restarted. (See the second bullet listed in restart policy details)
    
    unless-stopped 	
    Similar to always, except that when the container is stopped (manually or otherwise), it is not restarted even after Docker daemon restarts.
    

    Basic commands

    Command 	Description
    docker attach 	Attach local standard input, output, and error streams to a running container
    docker build 	Build an image from a Dockerfile
    docker builder 	Manage builds
    docker checkpoint 	Manage checkpoints
    docker commit 	Create a new image from a container’s changes
    docker config 	Manage Docker configs
    docker container 	Manage containers
    docker context 	Manage contexts
    docker cp 	Copy files/folders between a container and the local filesystem
    docker create 	Create a new container
    docker diff 	Inspect changes to files or directories on a container’s filesystem
    docker events 	Get real time events from the server
    docker exec 	Run a command in a running container
    docker export 	Export a container’s filesystem as a tar archive
    docker history 	Show the history of an image
    docker image 	Manage images
    docker images 	List images
    docker import 	Import the contents from a tarball to create a filesystem image
    docker info 	Display system-wide information
    docker inspect 	Return low-level information on Docker objects
    docker kill 	Kill one or more running containers
    docker load 	Load an image from a tar archive or STDIN
    docker login 	Log in to a Docker registry
    docker logout 	Log out from a Docker registry
    docker logs 	Fetch the logs of a container
    docker manifest 	Manage Docker image manifests and manifest lists
    docker network 	Manage networks
    docker node 	Manage Swarm nodes
    docker pause 	Pause all processes within one or more containers
    docker plugin 	Manage plugins
    docker port 	List port mappings or a specific mapping for the container
    docker ps 	List containers
    docker pull 	Pull an image or a repository from a registry
    docker push 	Push an image or a repository to a registry
    docker rename 	Rename a container
    docker restart 	Restart one or more containers
    docker rm 	Remove one or more containers
    docker rmi 	Remove one or more images
    docker run 	Run a command in a new container
    docker save 	Save one or more images to a tar archive (streamed to STDOUT by default)
    docker search 	Search the Docker Hub for images
    docker secret 	Manage Docker secrets
    docker service 	Manage services
    docker stack 	Manage Docker stacks
    docker start 	Start one or more stopped containers
    docker stats 	Display a live stream of container(s) resource usage statistics
    docker stop 	Stop one or more running containers
    docker swarm 	Manage Swarm
    docker system 	Manage Docker
    docker tag 	Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
    docker top 	Display the running processes of a container
    docker trust 	Manage trust on Docker images
    docker unpause 	Unpause all processes within one or more containers
    docker update 	Update configuration of one or more containers
    docker version 	Show the Docker version information
    docker volume 	Manage volumes
    docker wait 	Block until one or more containers stop, then print their exit codes
    

    Managing docker with portainer

    Create a volume

    docker volume create portainer_data
    

    Start portainer

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

    Pull ubuntu docker image

    docker pull ubuntu
    

    Running it interactively

    docker run -it ubuntu
    

    Listing out volumes

    docker ps -a
    

    Removing unused volumes

    docker rm -f <volume_name>
    

    Installing homer dashboard

    docker run --name=homer -d \
      -p 8001:8080 \
      -v /dkr/homer:/www/assets \
      --restart=always \
      b4bz/homer:latest
    
    

    Installing vscode codeserver

    ---
    version: "2.1"
    services:
      code-server:
        image: lscr.io/linuxserver/code-server
        container_name: code-server
        environment:
          - PUID=1000
          - PGID=1000
          - TZ=Asia/Dhaka
          - PASSWORD=password #optional
          - HASHED_PASSWORD= #optional
          - SUDO_PASSWORD=password #optional
          - SUDO_PASSWORD_HASH= #optional
          - PROXY_DOMAIN=code.ohidur.com
          - DEFAULT_WORKSPACE=/config/workspace #optional
        volumes:
          - /path/to/appdata/config:/config
        ports:
          - 8443:8443
        restart: unless-stopped
    

    Heimdall

    docker run --name=heimdall -d --restart=always -v /dkr/heimdall:/config -e PGID=1000 -e PUID=1000 -p 8004:80 -p 8005:443 linuxserver/heimdall
    

    Installing webtop

    ---
    version: "2.1"
    services:
      webtop:
        image: lscr.io/linuxserver/webtop:ubuntu-mate
        container_name: webtop
        privileged: true #optional
        security_opt:
          - seccomp:unconfined #optional
        environment:
          - PUID=1000
          - PGID=1000
          - TZ=Asia/Dock
          #- SUBFOLDER=/ #optional
        volumes:
          - /dkr/webtop:/config
          #- /var/run/docker.sock:/var/run/docker.sock #optional
        ports:
          - 5001:3000
        shm_size: "2gb" #optional
        restart: unless-stopped
      
    

    Ohidur Rahman Bappy
    WRITTEN BY
    Ohidur Rahman Bappy
    📚Learner 🐍 Developer