$curl https://get.docker.com/ > dockerinstall && chmod 777 dockerinstall && ./dockerinstall
2. Docker should now be installed, the daemon started, and the process enabled to start on boot. Check that it's running:
$service docker status
3. To check whether you can access and download images from Docker Hub, type:
$docker run hello-world
4. You can search for images available on Docker Hub by using the docker command with the search subcommand. For example, to search for the Ubuntu image, type:
$docker search ubuntu
In the OFFICIAL column, OK indicates an image built and supported by the company behind the project.
5. Once you've identified the image that you would like to use, you can download it to your computer using the pull subcommand, like so:
$docker pull ubuntu
After an image has been downloaded, you may then run a container using the downloaded image with the run subcommand. If an image has not been downloaded when docker is executed with the run subcommand, the Docker client will first download the image.
6. then run a container using it:
$docker run ubuntu
7. To see the images that have been downloaded to your computer, type:
$docker images
8. As an example, let's run a container using the latest image of Ubuntu. The combination of the -i and -t switches gives you interactive shell access into the container
$docker run -it ubuntu
9. Your command prompt should change to reflect the fact that you're now working inside the container and should take this form:
root@d9b100f2f636:/#
10. Now you may run any command inside the container.
$apt-get update
11. Then install any application in it. Let's install NodeJS, for example
$apt-get install -y nodejs
**When you start up a Docker image, you can create, modify, and delete files just like you can with a virtual machine. The changes that you make will only apply to that container. You can start and stop it, but once you destroy it with the docker rm command, the changes will be lost for good.
12. After using Docker for a while, you'll have many active (running) and inactive containers on your computer. To view the active ones, use:
$docker ps
13. To view all containers — active and inactive, pass it the -a switch:
$docker ps -a
14. To view the latest container you created, pass it the -l switch:
$docker ps -l
15. Stopping a running or active container is as simple as typing:
$docker stop container-id
(The container-id can be found in the output from the docker ps command.)
-- The next logical step after creating a new image from an existing image is to share it with a select few of your friends, the whole world on Docker Hub, or other Docker registry that you have access to. To push an image to Docker Hub or any other Docker registry, you must have an account there.
$docker login -u docker-registry-username
17. If you specified the correct password, authentication should succeed. Then you may push your own image using:
$docker push docker-registry-username/docker-image-name
18. -d for running process in background.
$docker run -d centos /bin/bash -c 'while true; do X=$[$X+1]; echo $X; sleep 1; done'
19. to see logs of container
$sudo docker logs $container_id or $name
20. to restart a container
$sudo docker restart containername
21. to remove images
$sudo docker rmi php
22. To remove container names hungry_hoppers
$sudo docker rm hungry_hoppers
If you want to remove running container then use -f
Let’s take the example of running apache. We know that apache runs on 80 port no. 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 apache container.
Environment variables if there are any.
$ docker run -d -p 80:80 --name my-apache-php-app -v "$PWD":/var/www/html php:7.2-apache$ docker run --name some-mysql -v /my/own/datadir:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
23. If you want to build a new image providing Dockerfile use following command.
$docker build -t imagename Dockerfile_location_path
Links:
https://hub.docker.com/_/mysql/