Friday, 6 January 2017

Create and manage Docker images on Windows and Docker Hub

To create a docker image on windows we need to install docker!

and start the docker service.

Once this has been done prepare a directory structure, where we will organise our Dockerfiles for each image:


Create a new directory containing a file named 'Dockerfile' for the image you wish to edit then cd to this directory edit the Docker file and once ready build the image:

# docker build -t [yourtag] 

to run the image interactively (cf login to the image) 

# docker run -i -t [yourtag] /bin/bash 

By logging in your can then test the further commands needed to build the image and add these to the docker file and repeat. Note, the images are not intended to be used as virtual machines and only one command can be run at the end (best to leave further commands to be run in the pipeline scripts; eg bitbucket pipeline will log you in 'interactively') 

You can start the Docker image exposing ports, to example, check the output of HTTP pages by mappng a port eg:

# docker run -i -i [yourtag] -p 8080:80 /bin/bash

If you were to start apache (inside the container) on port 80, then you should be able to view the web pages via http://localhost:8080/

Once happy upload to your docker hub account so that the images can be downloaded by tools like the bitbucket pipelines. 

# docker login 
# docker push [yourtag]

No comments:

Post a Comment