Monday 22 July 2019

Docker useful commands with respect to DevOps, Jenkins and Selenium

Having docker commands handy is always good to speed up your work. Following are few useful commands from docker.

Pre-Requisite: installing the docker. To install docker please refer docker installation

Docker handy commands:
'shows all the containers and images irrespective of their running status
docker ps -a

'shows all the containers and images which are currently running status
docker ps

'to pull any image from the docker hub. this command only pull the image to host docker
docker pull <image name>
Ex: docker pull mysql
docker pull jenkins
docker pull selenium/hub

'to run any of the image. some images required to pass some parameters but some images can run directly with simple command.
docker run mysql
docker run --name govardhan-wordpress --link govardhansql:mysql -p 8080:80 -d wordpress
'URL deployed from wordpress can be accessed with: http://localhost:8080/

docker run --name GovardhanJenkins -p 8083:8080 -p 50000:50000 -v /var/jenkins_home jenkins
'URL deployed from Jenkins can be accessed with: http://localhost:8083/

mysql image installation commands:
docker pull mysql  -- pull the image from the repository
docker run --name govardhansql -e MYSQL_ROOT_PASSWORD=abc123 -d mysql:latest

docker pull mysql  -- will pull from the repository
docker run mysql -- will run the image in the container

Running docker .yml file:
'running .yml file for with docker compose option. This option is quite easy compare to run the commands sequantially.
' copy the docker .yml file and run the below command from cmd problem or windows powershell after navigating to .yml file location/directory
'example: my docker file is located at C:\Govardhan\YYYYY\DevOps\Docker\wordpress
cd C:\Govardhan\YYYY\DevOps\Docker\wordpress
docker-compose up
' the above command automatically opens the .yml file and compose the docker to create container and run the image.

How to delete docker image:
'below command will delete images which are not associated to any containers
docker image prune -a

'Remove all images which aren’t associated with a running container: The -a parameter is the crucial bit here.
'If you want to force the action to occur without a confirmation prompt, you may add the -f parameter, like so:
docker image prune -af
Note: -af is the same as specifying -a and -f separately

Running Selenium Grid/Hub to execute Selenium scripts in parallel mode:
'to run the selenium grid in docker container, please run the following commands
'up selenium hub
docker run -d -p 4446:4444 --name GovardhanSelenium-hub -P selenium/hub
'to link with node chrome
docker run -d -P --link GovardhanSelenium-hub:hub selenium/node-chrome-debug
docker run -d -P --link GovardhanSelenium-hub:hub selenium/node-firefox-debug
' after this Selenium grid can be accessed with below URL
http://localhost:4446/grid/console

Inspect the docker image to find out the configuration details and other stuff:
docker inspect <image name/id>
example: docker inspect GovardhanJenkins

View the container generated log:
docker logs <image name/id>
docker logs GovardhanSelenium-hub
docker logs 93ebac97829d

1 comment:

  1. Ice Cream Soda - Sandia Rocks - Trikka Games
    Ice Cream Soda, is one babyliss pro titanium flat iron of babylisspro nano titanium spring curling iron the world's most titanium grey popular titanium tv apk products. Ice Cream Soda is made with ice cream titanium welder and fermented with fermented milk.

    ReplyDelete