Docker is a set of platform as a service (PaaS) products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels. Because all of the containers share the services of a single operating system kernel, they use fewer resources than virtual machines.
- Visit https://docs.docker.com/desktop/windows/install/
- Make sure
WSL 2 backend
is selected and download the installer. - Run the installer and restart PC when prompted to.
- Docker should start on system startup to finalize installation.
- When this error shows: Click on the link to go to Microsoft Docs page with the latest WSL2 kernel update. Then click on ‘download the latest WSL2 Linux kernel’ link on the page to download ‘wsl_update_x64’ setup file.
- Run the
wsl_update_x64
file - Verify installation by typing
docker version
in a command line. - Start docker, go to Settings --> Resources and tick
Enable integration with my default WSL distro
- Introduces the philosophy of Separation of Concerns and ensures Agile Development of software applications in both simple and complex domains.
- The standalone ability or independent nature of microservices open doors for following benefits:
- Reduces complexity by allowing developers to break into small teams, each of which builds/maintains one or more services.
- Reduces risk by allowing deployment in chunks rather than rebuilding the whole application for every change.
- Easy maintenance by allowing flexibility to incrementally update/upgrade the technology stack for one or more services, rather than the entire application in a single point in time.
- In addition to giving you the flexibility to build services in any language, thereby making it language independent, it also allows you to maintain separate data models of each of the given services.
- You can build a fully automated deployment mechanism for ensuring individual service deployments, service management and autoscaling of the application.
docker run image_name
docker build -t account_id/image_name/tag
docker push image_name
docker stop container_id
docker rmi image_name
docker rmi image_name -f
account_id/image_name/tag
vimitre/app/v1
If tag is not provided, it will be 'latest'.
docker pull image_name
- Example:
docker pull ahskhan/sparta-app-dockerised:v1
ghost
imagedocker run -d -p 2368:2368 ghost
docker ps
ordocker ps -a
To open a shell in container:
docker exec -it container_id bash
- If there is an error, run this:
alias docker="winpty docker"
To send a command to run in container:
docker exec -it container_id bash -c command
docker run -d -p 4000:4000 docke/docker.github.io
docker run -d -p 80:80 nginx
- Create repository on DockerHub:
sre_customised_nginx
- Create a new index page
- Copy the index.html file to the default location of nginx' index page:
docker cp index.html 3adb9f0cbb05:/usr/share/nginx/html/
- Commit the change:
docker commit 3adb9f0cbb05 sre_customised_nginx
- Push it to DockerHub:
docker push vimitre/sre_customised_nginx
- Check if it worked:
docker run -d -p 80:80 vimitre/sre_customised_nginx
- Create a
Dockerfile
:
# Choose image
FROM nginx
LABEL MAINTAINER=vimitre
# Copy local index.html to container
COPY index.html /usr/share/nginx/html/
# port 80
EXPOSE 80
# CMD to launch the nginx web server
CMD ["nginx", "-g", "daemon off;"]
- Build the image:
docker build -t vimitre/sre_nginx_test:v1 .
- Push it:
docker push vimitre/sre_nginx_test
- Build an image for the app
- Select
node
image LABEL
COPY
dependencies from localhost to containerapp
/default location- Copy package.json files
RUN npm install
RUN npm install express
RUN node seeds/seed.js
EXPOSE 3000
CMD ["node", "app.js"]
FROM node
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install -g npm@latest
RUN npm install express
# RUN node seeds/seed.js
COPY . .
EXPOSE 3000
CMD ["node", "app.js"]
- Run it:
docker run -d -p 80:3000 vimitre/sre_node_app:v1
To stop all containers: docker rm -f $(docker ps -a -q)
docker history image_name
docker compose up -d
docker compose down
- List available volumes:
docker volume ls
- Create volume:
docker volume create volume_name
- Inspect volume:
docker inspect volume volume_name
- Delete volume:
docker volume rm sre_viktor