What is Docker?
Docker is a tool designed to make it easier to create, deploy, and run applications by using containers.
Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies and ship it all out as one package.
By doing so, thanks to the container, the developer can rest be assured that the application will run on any other Linux machine regardless of any customized settings that machine might have that could differ from the machine used for writing and testing the code.
With Docker, you need not be dependent upon the underlying operating system, if it can install and run docker, it can easily run your application in the same way it runs an application on any other machine.
You can easily launch any docker container and destroy it in a fraction of seconds.
So how can it help you guys?
- You don’t have to worry about, “it works on the testing server but not on the production server”.
- You can work with various versions of various languages at the same time. (You have 2 projects running one in php5.6 and one in php7.1, still no issue, you can run it anytime on the same system)
- You can create/destroy different versions of any software in one command.
How does it work?
Docker creates an abstraction layer for the system.
– Docker is light-weight, it only installs dependencies that are required for particular applications to run, not even the whole Operating System.
– In one command you can install different versions and can remove it.
– No dependency error while installing any software because it creates its’ own space and which is abstracted with other installed programs.
How to install Docker (Ubuntu Users)
curl https://get.docker.com/ > dockerinstall && chmod 777 dockerinstall && ./dockerinstall
How to install Docker (MAC OS Users)
- Login into Docker and download Docker.dmg file from there
- Then follow steps given here
To check the docker version and if it’s installed properly or not
Docker Images and Docker containers
- Docker images are like iso file.
- In docker images, the required packages are written so when you run a particular docker image it creates a container and runs all the commands written in the docker image
Where can you find docker images?
- Docker hub
- Hosted on AWS
- Hosted on Google cloud
- Create your own
Run your first docker application
1. Pull Docker image :
- If docker images on docker hub simple type docker pull $imagename
- If it’s on AWS then give its full path and authenticate your role to pull that image
2. Run Docker image :
- Let’s take the example of running apache. We know that apache runs on 80 port number by default.
- We need to mount a volume of apache’s configuration file so we can anytime change it without getting into the container
- We need to expose 80 port to our system. So we can access the apache container.
- Environment variables if there are any.
Let’s take one more example of deploying MySQL Container
docker run --name some-mysql -v /my/own/datadir:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
Drafted on: 26th December 2019