Skip to content

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.

Recently, i've gained this simple knowledge of realizing a newly developed, opensource like programming language made available to the general public, which resembled a derivative of C/C++ with some resemblance to C#. A natural language of the robots called Beef. Once, i had cloned the github repo onto both 18.04 ubuntu on (VM/metal) along with cloning directly to a Mac running the latest version of the Xcode, all three occurrences when compiling this software failed miserably.

Fail on Linux VM ubuntu 18.04.x
collect2: fatal error: ld terminated with signal 9 [Killed]
compilation terminated.
tools/lto/CMakeFiles/LTO.dir/build.make:278: recipe for target 'lib/' failed
make[2]: *** [lib/] Error 1
make[2]: *** Deleting file 'lib/'
CMakeFiles/Makefile2:20778: recipe for target 'tools/lto/CMakeFiles/LTO.dir/all' failed
make[1]: *** [tools/lto/CMakeFiles/LTO.dir/all] Error 2
Makefile:151: recipe for target 'all' failed
make: *** [all] Error 2

Failed on MAC Catalina w/Xcode
/Users/flo/github/Beef/BeefySysLib/platform/darwin/../posix/PosixCommon.cpp:1360:1: warning: control reaches end of non-void function
1 warning generated.
[100%] Linking CXX static library ../Release/bin/libBeefRT.a
/Applications/ file: ../Release/bin/libBeefRT.a(StompAlloc.cpp.o) has no symbols
/Applications/ file: ../Release/bin/libBeefRT.a(StompAlloc.cpp.o) has no symbols
[100%] Built target BeefRT
Building BeefBuild_bootd
TIMING: Beef compiling: 60.2s
Linking BeefBuild_bootd...Undefined symbols for architecture x86_64:
  "_ffi_call", referenced from:
      bf::System::FFI::FFILIB::Call(bf::System::FFI::FFILIB::FFICIF*, void*, void*, void**) in libBeefRT_d.a(Internal.cpp.o)
  "_ffi_closure_alloc", referenced from:
      bf::System::FFI::FFILIB::ClosureAlloc(long, void**) in libBeefRT_d.a(Internal.cpp.o)
  "_ffi_prep_cif", referenced from:
      bf::System::FFI::FFILIB::PrepCif(bf::System::FFI::FFILIB::FFICIF*, bf::System::FFI::FFIABI, int, bf::System::FFI::FFIType*, bf::System::FFI::FFIType**) in libBeefRT_d.a(Internal.cpp.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
FAIL: Exit code returned: 1

Failed on hardware Ubuntu 18.04.
This was the machine, which gotten to the linking section.
cannot find -ltinfo
build.make:194: recipe for target 'Debug/bin/BeefBoot' failed
build.make:253: recipe for target 'BeefBoot/CMakeFiles/BeefBoot.dir/all' failed

Compiled it 4 times and each time had different failed messages when using MAC and Linux. If anyone has a solution to either compiling failures, let me know. reach me at aschenbach at gmail com.

A quick note about how to upload a newly created container from docker hub by adding additional software before uploading it to docker hub. I am not as familiar with this favor of linux. Alpine is different from other linux and used a different package manager to install additional software. This distro we are using in our example is called Alpine linux. On Docker Hub, it is super light weight and came with a old Shell from unix. In this example, we will pull this docker image, add the BASH , commit it and package it then finally upload this new version to your Docker hub Free Account.

Pure example only for my personal recollection/ fullfillment.
flo@box: ~ $ docker pull alpine
# docker run -t -d --name {NameOfYourDockerInstance} alpine
flo@box: ~ $ docker run -t -d --name alpine_bash alpine
flo@box: ~ $ docker images
# docker exec -it {NameOfYourDockerInstance} sh
flo@box: ~ $ docker exec -it alpine_bash sh

Now, we are inside this instance of alpine as a virtualized container. We must now add additional software to this container before exiting it. Since our example is to install our favorite shell called bash. We will do so inside this container.

the prompt for alpine looked like this:
/ #
/ # apk update
/ # apk upgrade
/ # apk install bash
/ # exit

DONE with Alpine.

Now, you will have to log into your docker hub account and create a new public repo to hold this container from your local machine. Once done, the following instructions will apply to push this local instance to Docker hub.

Docker notation stated the following:
docker commit [options] [container ID] [repository:tag]

In my Docker hub container, i've named my local container as: alpine_bash.

flo@box : ~ $ docker container ps -a # will show the following
352b8a99458f alpine "/bin/sh" 8 seconds ago Up 7 seconds alpine_bash

We want to use the container ID as a parameter then the Dockerhub PUBLIC container you've created to hold this Docker Instance then some version reference which is shown after the colon.

flo@box: ~ $ docker commit 352b8a99458f freemanbach/nixcontainer:0.0.1

Before pushing your local docker instance to the cloud, you may want to consider using this command to authenticate with Docker Cloud service

flo@box: ~ $ docker login

flo@box: ~ $ docker push freemanbach/nixcontainer:0.0.1


Just something to remember how this works and what it associated with when using a containerized Application such as docker and how it could benefit System Engineering and Administration.

Due to the sake of simplicity, let us use a linux (host) machine called box and with a username as flo. {NameOfYourDockerInstance} is the name of the docker instance you will give on your local machine.

Pulling OS from docker Hub
flo@box: ~ $ docker pull centos # other OS listed on DockerHub

Name your OS instance
flo@box: ~ $ docker run -t -d --name {NameOfYourDockerInstance} centos

Show what is running inside docker
flo@box: ~ $ docker ps

Execute the software inside this Docker instance
flo@box: ~ $ docker exec -it {NameOfYourDockerInstance} bash

Check the status of your docker instances
flo@box: ~ $ docker stats

To Stop/Start Docker Instance
flo@box: ~ $ docker start/stop {NameOfYourDockerInstance}

When and if by chance that you have forgot to add a port to a Docker container. One can search for this file called hostconfig.json in your host OS and make changes to the container you wish to reconfigure. A second approach might be to stop the instance, commit a copy from a source instance to a destination instance then using the run command to finally add the port.

flo@box: ~ $ docker stop cake
flo@box: ~ $ docker commit cake cake2
flo@box: ~ $ docker run -t -d -p 8080:8080 cake2
flo@box: ~ $ docker exec -it cake2 bash