Learn docker command to create docker image, build docker image, start docker container to test the image, docker tag to label and version your images and finally push the newly created build image to your docker hub repository by using docker push command.
Command:
- Clone github repository: git clone repo_link
- Navigate into the newly create directory: cd directory_name
- Run the following command to build docker image swapping out YOUR_DOCKER_USERNAME with your USERNAME: docker build -t YOUR_DOCKER_USERNAME/docker-quickstart .
NOTE: Make sure you include the dot (.) at the end of the docker build command. This tells Docker where to find the docker file.
- Run the following command to list the newly created docker image: docker images
- Start the container to test the image by running the following command: docker run -d -p 8080:8080 YOUR_DOCKER_USERNAME/docker-quickstart (you can verify if the container is working by visiting localhost:port_number)
- Use the docker tag command to tag the docker image. Docker tag allow you to label and version your images.
command: docker tag YOUR_DOCKER_USERNAME/docker-quickstart YOUR_DOCKER_USERNAME/docker-quickstart:1.0
- Finally, it's time to push the newly build image to your Docker Hub repository by using docker push command: docker push YOUR_DOCKER_USERNAME/docker-quickstart:1.0