Sources: docs.docker.com
Downloaded .deb for ubuntu from :
https://download.docker.com/linux/ubuntu/dists/trusty/pool/stable/amd64/docker-ce_17.06.0~ce-0~ubuntu_amd64.deb
dpkg -i docker-ce_17.06.0~ce-0~ubuntu_amd64.deb
#1:- unable to prepare context: unable to evaluate symlinks in Dockerfile path
Soln: docker build -f docker.txt -t test_img #Got following error as docker service is running as root and have not configured for other users..
#2:- Got permission denied while trying to connect to the Docker daemon socket at unix
Soln: sudo docker build -f docker.txt -t test_img #At this time my docker.txt is empty.. hence got following error..
#3:- Error response from daemon: the Dockerfile (docker.txt) cannot be empty
Soln: Added following :
RUN echo "Hello world"; #and landed in below error.
#4:-Please provide a source image with `from` prior to run
Soln: Search for proper image as per requirement and add "FROM img_name" on first line in docker.txt
#5:- Post http:///var/run/docker.sock/v1.19/build?cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=dockerFile&memory=0&memswap=0&rm=1&t=kimberlyclark: dial unix /var/run/docker.sock: permission denied. Are you trying to connect to a TLS-enabled daemon without TLS?
Soln: chmod 777 /var/run/docker.sock
#How it works?
Simple :) docker instruction file AKA dockerFile is created on source system. In dockerFile we define a container image and deployment activities to be performed on defined container in desired sequence. Later image is build and run, if run success and we get desired output on source system, then same docker file(along with all sources referred in it) will be used on target system.
docker build -f <DOCKER_FILE> -t <NEW_IMAGE_NAME> . #e.g- docker build -f docker.txt -t test_img.
docker run <NEW_IMAGE_NAME> #e.g- docker run test_img
docker run --expose <PORT_NUMBER> <NEW_IMAGE_NAME> #e.g- docker run test_img and if application is opening some port then it has to be exposed using --expose followed by PORT or IPADDRESS:PORT
docker run -p <PORT_NUMBER>:<PORT_NUMBER> <NEW_IMAGE_NAME> #for VPC's port forwarding. stackoverflow
#Sample docker.txt
FROM node:8
RUN ls
RUN mkdir /projects/puppeteer_impl/output -p
WORKDIR /projects/puppeteer_impl
COPY ./* ./
ADD node_modules /projects/puppeteer_impl/node_modules/
CMD ["node", "-v"]
CMD ["ls"]
CMD ["npm", "install"]
CMD ["node", "puppeteer_impl.js"]
#In my source folder there are files & folder which I dont want docker to copy in image while build.
create .dockerignore file beside dockerFile with list of files folders to be ignored. following is sample content.
node_modules
package-lock.json
#Few usefull commands for basic "how to" questions..
docker info #returns basic info about docker(e.g.- # of Container, disk usage etc.. )
docker ps #Lists all available container. Option '-a' provides details of all available containers(states- run/stop).
docker images #Lists all available/built image. Option '-a' provides details of all images(states- run/stop/download as support images).
docker rmi <IMAGE_ID_FROM_OUTPUT_OF_ABOVE> #removes all listed imageIds
docker stop <CONTAINER_ID> #shuts specified container
docker rm <CONTAINER_ID> #removes all listed containers
docker run -it <IMAGE_NAME> /bin/bash #gets you into bash of running container just after execution of last CMD in DockerFile.
docker exec -it <CONTAINER_ID> /bin/bash #gets you into bash of running container.
docker cp <CONTAINER_ID>:/file/path/within/container /host/path/target #to take file out of container into local system.
docker logs <CONTAINER_ID> #shows logs from container
docker inspect <CONTAINER_ID> #description about container, it's ipaddress and others.
Installation in wsl ubuntu.. - 20240309