From 426bd73c516c4df8cb745a32d19334c5167cc629 Mon Sep 17 00:00:00 2001 From: JasonHomeWorkstationUbuntu Date: Mon, 7 Dec 2020 16:02:29 +1100 Subject: [PATCH] First Dockerhub public image --- README.md | 43 ++++++++++++++++++++++++- docker-compose.yaml | 23 +++++++++++++ first-public-dockerhub-image/Dockerfile | 3 ++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 docker-compose.yaml create mode 100644 first-public-dockerhub-image/Dockerfile diff --git a/README.md b/README.md index c9b02aa..6068d41 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,44 @@ # README -This repository is a playground for practising docker based programming following [docker-development-youtube-series](https://github.com/marcel-dempers/docker-development-youtube-series) \ No newline at end of file +This repository is a playground for practising docker based programming following [docker-development-youtube-series](https://github.com/marcel-dempers/docker-development-youtube-series) + +## Three Problems for docker beginner + +1. Programmer need be able to navigate through windows/mac/linux OS using cmd line fluently: + 1. `ls/dir` for list files + 2. `cd` for move through file systems +2. Working Directories + 1. Show current working directory `echo $PWD` + 2. Don't hardcode path to file in docker files +3. Understand *docker volume* `docker run -v hostPath:containerPath` + 1. e.g. `docker run -it -v $PWD:/work -w /work alpine:3.9 /bin/sh` + +## dockerfile + +Before bring up docker container, we need first create `dockerfile` to describe the image that we want to use to create containers. + +For different languages, `c#`, `golang` & `python` each has a separate dockerfile. Each describe the complete environment can be used to develop corresponding programs + +## Docker compose + +`Compose` is an **orchestration** tool that used to spinning up multi-container distributed applications, it shipped with Docker by default. It's not ideal for large system setup, but great for development purpose and testing + +It's easy to define a multi-container app and accompanying services using **one single file**, and start it using single command. We can also build/push images to registry using `docker-compose` + +The compose file is `docker-compose.yaml` in PWD + +* Build image individually: `docker-compose build ` +* Build all images: `docker-compose build` + +### Create & Push images built from docker-compose + +1. Create image using `docker-compose.yaml` & `Dockerfile` + 1. Write `Dockerfile` and `docker-compose.yaml` + 2. Create image: `docker-compose build first-public-dockerhub-image` where + 1. `first-public-dockerhub-image` is the service name of the image +2. Login Docker hub + 1. `docker login`, without specify server address, it automatically connect to DockerHub + 2. Enter Username & Password + 3. Now computer has login DockerHub successfully +3. Go to Docker hub, create the `first-public-dockerhub-image` repository +4. Go to command line, push the image `docker push cruxligh/first-public-dockerhub-image` \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..dd0c296 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,23 @@ +version: "3" +services: + csharp: + container_name: csharp # image name + image: /csharp_sdk:1.0.0 + build: + context: ./c# + golang: + container_name: golang + image: /golang_sdk:1.0.0 + build: ./golang + nodejs: + container_name: nodejs + image: /nodejs:1.0.0 + build: ./nodejs + python: + container_name: python + image: /python:1.0.0 + build: ./python + first-public-dockerhub-image: + container_name: first-public-dockerhub-image + image: cruxlight/first-public-dockerhub-image:latest + build: ./first-public-dockerhub-image \ No newline at end of file diff --git a/first-public-dockerhub-image/Dockerfile b/first-public-dockerhub-image/Dockerfile new file mode 100644 index 0000000..f9960d4 --- /dev/null +++ b/first-public-dockerhub-image/Dockerfile @@ -0,0 +1,3 @@ +FROM busybox +CMD echo "Hello world! This is my first Docker image." +CMD echo "Some change" \ No newline at end of file