Example of taking a docker image and modifying it using a Dockerfile
This dockerfile will specify an initial docker image and perform some tasks on it. This will result in the creation of a new image when we issue the docker build command.
In the following Dockerfile, we do the following:
Dockerfile
FROM jamesdbloom/mockserver LABEL placodermi.component=mockserver WORKDIR /opt/mockserver # Artifacts COPY entrypoint.sh /opt/mockserver/entrypoint.sh COPY MockInitializer.java /opt/mockserver/MockInitializer.java RUN chmod +x /opt/mockserver/entrypoint.sh EXPOSE 1080 EXPOSE 1090 ENTRYPOINT ["/opt/mockserver/entrypoint.sh"] |
Run the Dockerfile by issuing the following command
docker build -t <image_name> . ( <-- don't miss that dot )
ie. > docker build -t mockserver_image .
The above command will run the Dockerfile and create a new image with the <image_name> specified by the -t option.
If something goes wrong, you can remove the created image by issuing the following command:
docker rmi <image_name>
ie. > docker rim mockserver_image
Now that you have your image, you can run this image by issuing the following command:
docker run -it --rm <image_name>
ie. > docker run -it --rm mockserver_image
If you run into an error running the image, you can bypass your entrypoint and then access the filesystem. This may help diagnose the problem.
To log into your image issue the following command:
docker run -it --rm --entrypoint bash <image_name>
ie. > docker run -it --rm --entrypoint bash mockserver_image
Now that you have confirmed that the image works, you can make it a container by issuing the following command:
docker run -d -p <ex_port>:<int_port> -- name <container_name> <image>
ie. > docker run -d -p <ex_port>:<int_port> -- name mockserver mockserver_image
That's the general basics of it all.