Docker


Docker install on Debian Linux

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -

sudo apt-get install apt-transport-https ca-certificates curl gnupg2 software-properties-common

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"

sudo apt update && sudo apt install docker-ce

sudo docker run -it bash  # it means interactive

sudo docker images # list images

sudo docker ps # list containers

sudo docker stop containername # stop container

sudo docker rm containername # remove container 

sudo docker rmi -f imageid  # remove image

sudo docker system prune  # clean up

sudo docker volume create 

sudo docker network create

Docker build small php app

create a folder src

create a index.php echo “Hello World” >> index.php

create a docker file

FROM php:7.0-apache
COPY . /var/www/html
EXPOSE 80

from the src folder run docker build -t hello-world .

docker run -p 80:80 hello-world this publishes the ports right side is container port and left side is host port

docker run -p 80:80 -v /home/vagrant/src/:/var/www/html/ hello-world this shares the host volume (left) with the container volume (right)

Portainer container management app

$ docker volume create portainer_data
$ docker run -d -p 9000:9000 -p 8000:8000 --name portainer --restart always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer

Sample nodejs app

git clone https://github.com/dockersamples/node-bulletin-board

cd node-bulletin-board/bulletin-board-app

Sample Dockerfile

# Use the official image as a parent image.
FROM node:current-slim

# Set the working directory.
WORKDIR /usr/src/app

# Copy the file from your host to your current location.
COPY package.json .

# Run the command inside your image filesystem.
RUN npm install

# Inform Docker that the container is listening on the specified port at runtime.
EXPOSE 8080

# Run the specified command within the container.
CMD [ "npm", "start" ]

# Copy the rest of your app's source code from your host to your image filesystem.
COPY . .

Build command is

docker build --tag bulletinboard:1.0 .

docker run --publish 8000:8080 --detach --name bb bulletinboard:1.0 # 8000 is host port, and 8080 is container port

These writings represent my own personal views alone.
Licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.