Skip to content

Docker: Can you script the Docker, like a Boss ? (part 3)

The Simple answer is yes, one can script the docker like a Boss. Kind of struggled this semester trying to make sense what Docker is and what Docker can do for System Engineering as a whole. My struggle was to understand how does a local installation of Docker be able to connect to DockerHub. This was my one and only struggle ! After realizing that all of the files (images) aka resources were coming from this Dockerhub website, I was in an absolute euphoric state, once this had been resolved. A LED lightbulb had woken me up in a deep slumber and everything made sense.

The Key is how to write commands in order to control the delivery of these Software images into your local machine (mac, windows, linux). Once an image has been pull from DockerHub, one has the ability to customize an image. One has the ability to make an image from Dockerhub to a single instance of that image, or to as many as thousands of local instances of that one particular image. These Local Runnable images can then be copied with unique customization then turned into Containers. After customization, one would run the containers, altered its configs, add features, and finally delete them, if necessary.

For example: the following 10 lines of code can be saved into a file called: Dockerfile. Once the code has been inserted into this special file. One can run this file in your terminal and execute all the commands. Your supervisor would be impressed that you are busy ! **b/c the longer this file is, the more text will fly across your terminal like a screen saver.

# This is a Docker Script

FROM ubuntu
ENV PATH /usr/local/bin:$PATH
RUN set -eux; \
apt-get update -y; \
apt-get install -y wget; \
apt-get install -y vim; \
apt-get install -y apache2; \
apt-get install -y mariadb
ENTRYPOINT ["/usr/sbin/apache2ctl", "start"]

so.. now, you asked yourself, what do you do with the code from above ? right, in your OS, do a few things add that script and save it as Dockerfile.

mkdir $HOME/dockerimg
# copy that code from above and save it inside this $HOME/dockerimg location as "Dockerfile"
# to build this dockerscript, you can run the following command.
docker build -t NameofYourContainer:latest .

Now, you will see all kinds of text fly across your screen as if you are super busy doing something. You can also push it to your dockerhub account but one problem is that some of these images are pretty large. Unless that you have paid for a dockerhub account, generally its not allow to upload more than a a certain size of your image to dockerhub.

Leave a Reply

Your email address will not be published. Required fields are marked *