Step by Step simplest Docker container
MD
R
MarkdownWe will be creating the simplest docker container image which can run any bash script.
Recipe: Create the Simplest Custom Image and Container
- All Docker Containers require a basic linux operating system running. I recommend Alpine Linux for simple Containers
- Create the Dockerfile (this the "flow" file and contains a sequencial execution flow of docker commands) touch Dockerfile
- Add the Linux distribution FROM alpine
- Add a PID1 process for Entry Point, Usually the Entry Point is used to load and check environment variables, run provisioning scripts. Dumb-Init: Keeps the container safe, blocks I/O events, has basic exception handling ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 /usr/local/bin/dumb-init RUN chmod +x /usr/local/bin/dumb-init
- Add a basic shell script to run touch run.sh chmod +x run.sh
#! bin/sh
echo "EXEC ALL ARGUMENTS..."
exec "$@"
echo "start your server here"
- Add a run command to copy the file from the local folder to the container, set executable permissions on the containers' copy COPY script.sh /run.sh RUN chmod +x /run.sh
- Add a CMD command to start both dumb-init and the run script CMD ["dumb-init", "/run.sh"]
- Build the docker container image docker build .
- Note down the hash name of the container 'Successfully built <b625dd6f62ae>'
- Create & Start an instance of our container docker run --name simple b625dd6f62ae
- Remove the container docker rm simple
Created on 6/15/2017