-
-
Save junaidulqayyumqureshi/6da6c010a50677f44af3b4622a2172ea to your computer and use it in GitHub Desktop.
Docker |
Source
https://www.youtube.com/watch?v=Kyx2PsuwomE
Installing Nginx
docker run -it -p 3031:80 nginx
3031:80 means that 3031 port which is on this system, map it to port on which service will listen, which is 80
Installing Apache Httpd
docker pull httpd
OR
docker run -d -p 3032:80 --name apacheserver httpd
Installing MySQL
docker run -d -p 3306:3306 --name mySql-db --env MYSQL_ROOT_PASSWORD=123456 mysql
Environment variables i.e. MYSQL_ROOT_PASSWORD can be seen in https://hub.docker.com/_/mysql on docker hub
Bind Mount
docker run -d -p 3031:80 -v D:\Tutorials\Docker\website:/usr/share/nginx/html --name nginx-website nginx
Source
https://www.youtube.com/watch?time_continue=209&v=jTeDNXLFYjE&feature=emb_logo
After the path is linked, create a new index.html file, to override the image directory index.html file which is located in /usr/share/nginx/html
Dockerfile
FROM nginx:latest
WORKDIR /usr/share/nginx/html
COPY . .
Build docker image
docker image build -t hublogin/imagename [path-to-dockerfile]
ie. docker image build -t juniallomate/nginx-website .
Push image to your repository on hub.docker
docker push juniallomate/nginx-website
In case of Access Denied Error
docker login
Source
https://www.youtube.com/watch?v=bDB4IfJ31HY
Search for image from CLI
docker search --filter=stars=680 mysql
WHERE --filter-starts means only those entries which have n starts or more
Source
https://www.youtube.com/watch?v=HUpIoF_conA
Docker Compose
Tool for defining multi-container structured docker
Check docker version
docker-compose -v
Filename: docker-compose.yml
Bash into nginx:
docker exec -it container_name /bin/bash
To run an existing or non-existing image
docker run ubuntu
It means to run a container with this image on it
To pull/download an image from docker hub registry
Docker images
docker images
Remove docker image
Restart a container
docker restart containerId
To show running containers
docker ps
To show containers regardless
docker ps -a
To delete containers with ContainerID from docker ps command
docker rm 305297d7a235 ff0a5c3750b9
Deleting mulitple containers at once
To delete all the containers which exited and not running at the moment
docker rm $(docker ps -a -q -f status=exited)
Deleting all the exited containers at once can also be achieved through this command
docker container prune
Docker detached & attached
To stop a container
docker stop containerID/containerName
Finally, to run an image on a container
_WHERE
-d Detached
-p Exposing to ports
--name Display name of container when docker ps
_
Exposing ports meaning
What
8080:80
means is that:8080 will be the port on which your local system will connect to docker ie. localhost:8080
80 will be the port which docker will request on to the container with ie. nginx:80
Dockerfile
Set of instructions, which help create a new image. Just like the images, we download from registry.
When
docker build
command runs, it searched for a filename Dockerfile. It can be changed, but not recommendedFile Dockerfile (without any extension, case-sensitive)
Dockerfile contents
FROM baseimg
WHERE baseimg is any image i.e. ubuntu, nginx etc which is the base of this complete image
Terminologies
Images Apps that are running on the containers, i.e. ubuntu
Containers Created/Instantiated from an image
Daemon Service that is responsible for all the docker actions, i.e managing containers etc
Docker Hub Docker registry from where the images are pulled