1654800120
dfg
is both a go library and an executable that produces valid Dockerfiles using various input channels.
dfg
is a Dockerfile generator that accepts input data from various sources, produces and redirects the generated Dockerfile to an output target such as a file or stdout.
It is especially useful for generating Dockerfile instructions conditionally since Dockerfile language has no control flow logic.
curl -o dfg -L https://github.com/ozankasikci/dockerfile-generator/releases/download/v1.0.0/dfg_v1.0.0_darwin_amd64
chmod +x dfg && sudo mv dfg /usr/local/bin
curl -o dfg -L https://github.com/ozankasikci/dockerfile-generator/releases/download/v1.0.0/dfg_v1.0.0_linux_amd64
chmod +x dfg && sudo mv dfg /usr/local/bin
curl -o dfg.exe -L https://github.com/ozankasikci/dockerfile-generator/releases/download/v1.0.0/dfg_v1.0.0_windows_amd64.exe
go get -u github.com/ozankasikci/dockerfile-generator
Available commands:
dfg generate --input path/to/yaml --out Dockerfile
generates a file named Dockerfile
dfg generate --input path/to/yaml --target-field ".server.dockerfile" --out Dockerfile
generates a file named Dockerfile
reading the .server.dockerfile
field of the YAML file.
dfg generate --help
lists available flags
When using dfg
as a go library, you need to pass a []dfg.Stage
slice as data. This approach enables and encourages multi staged Dockerfiles. Dockerfile instructions will be generated in the same order as in the []dfg.Instruction
slice.
Some Instruction
s accept a runForm
field which specifies if the Instruction
should be run in the shell form
or the exec form
. If the runForm
is not specified, it will be chosen based on Dockerfile best practices.
For detailed usage example please see Library Usage Example
stages
key on top level)stages:
final:
- from:
image: kstaken/apache2
- run:
runForm: shell
params:
- apt-get update &&
- apt-get install -y
- php5
- libapache2-mod-php5 &&
- apt-get clean &&
- rm -rf /var/lib/apt/lists/*
- cmd:
params:
- /usr/sbin/apache2
- -D
- FOREGROUND
Use dfg as binary:
dfg generate -i ./example-input-files/apache-php.yaml --stdout
Or as a library
data, err := dfg.NewDockerFileDataFromYamlFile("./example-input-files/apache-php.yaml")
tmpl := dfg.NewDockerfileTemplate(data)
err = tmpl.Render(output)
FROM kstaken/apache2
RUN apt-get update && apt-get install -y php5 libapache2-mod-php5 && apt-get clean && rm -rf /var/lib/apt/lists/*
CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"]
someConfig:
key: value
serverConfig:
dockerfile:
stages:
final:
- from:
image: kstaken/apache2
- run:
runForm: shell
params:
- apt-get update &&
- apt-get clean &&
- rm -rf /var/lib/apt/lists/*
Use dfg as binary:
dfg generate -i ./example-input-files/test-input-with-target-key-6.yaml --target-field ".serverConfig.dockerfile" --stdout
Or as a library
data, err := dfg.NewDockerFileDataFromYamlField("./example-input-files/test-input-with-target-key-6.yaml", ".serverConfig.dockerfile")
tmpl := dfg.NewDockerfileTemplate(data)
err = tmpl.Render(output)
FROM kstaken/apache2
RUN apt-get update && apt-get clean && rm -rf /var/lib/apt/lists/*
package main
import dfg "github.com/ozankasikci/dockerfile-generator"
func main() {
data := &dfg.DockerfileData{
Stages: []dfg.Stage{
// Stage 1 - Builder Image
// An instruction is just an interface, so you can pass custom structs as well
[]dfg.Instruction{
dfg.From{
Image: "golang:1.7.3", As: "builder",
},
dfg.User{
User: "ozan",
},
dfg.Workdir{
Dir: "/go/src/github.com/ozankasikci/dockerfile-generator/",
},
dfg.RunCommand{
Params: []string{"go", "get", "-d", "-v", "golang.org/x/net/html"},
},
dfg.CopyCommand{
Sources: []string{"app.go"}, Destination: ".",
},
dfg.RunCommand{
Params: []string{"CGO_ENABLED=0", "GOOS=linux", "go", "build", "-a", "-installsuffix", "cgo", "-o", "app", "."},
},
},
// Stage 2 - Final Image
[]dfg.Instruction{
dfg.From{
Image: "alpine:latest", As: "final",
},
dfg.RunCommand{
Params: []string{"apk", "--no-cache", "add", "ca-certificates"},
},
dfg.User{
User: "root", Group: "admin",
},
dfg.Workdir{
Dir: "/root/",
},
dfg.CopyCommand{
From: "builder", Sources: []string{"/go/src/github.com/ozankasikci/dockerfile-generator/app"}, Destination: ".",
},
dfg.Cmd{
Params: []string{"./app"},
},
},
},
}
tmpl := dfg.NewDockerfileTemplate(data)
// write to a file
file, err := os.Create("Dockerfile")
err = tmpl.Render(file)
// or write to stdout
err = tmpl.Render(os.Stdout)
}
FROM golang:1.7.3 as builder
USER ozan
WORKDIR /go/src/github.com/ozankasikci/dockerfile-generator/
RUN go get -d -v golang.org/x/net/html
COPY app.go .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
FROM alpine:latest as final
RUN apk --no-cache add ca-certificates
USER root:admin
WORKDIR /root/
COPY --from=builder /go/src/github.com/ozankasikci/dockerfile-generator/app .
CMD ["./app"]
Author: Ozankasikci
Source Code: https://github.com/ozankasikci/dockerfile-generator
License: GPL-3.0 license
1647401200
Stephen Kuenzli has designed, built, deployed, and operated highly available, scalable software systems for nearly 20 years. In this live coding session, Stephen showcases how to build images automatically with Dockerfiles and patterns for tagging them.
📚📚📚
This video references the book | Docker in Action, Second Edition
Get it here: http://mng.bz/aD0B
For 40% discount use the code: watchkuenzli40
📚📚📚
About the book:
Docker in Action, Second Edition" teaches you to create, deploy, and manage applications hosted in Docker containers running on Linux. Fully updated, with four new chapters and revised best practices and examples, this second edition begins with a clear explanation of the Docker model. With examples showing how Docker benefits the whole dev lifecycle, you’ll discover techniques for everything from dev-and-test machines to full-scale cloud deployments.
#docker #dockerfiles #devops
1625886946
We will learn how to create docker image of Node.js app/service. There are lots of article already on this topic but they have lack of simplicity. When I went through them to create my first docker image. I realized they are complicated. But making a docker image of Node.js app is not as tough as it seems.
I am assuming that you already have knowledge of working in Node.js. Here I will not go through creating a Node.js project. You can refer this repo for code.
When you start learning Docker, two main terms come up
In this article, we will learn about Images.
A docker image is collection of files that bundle together all essentials (installations, application code and dependencies) required to configure a fully operational container environment. In simple words, it bundle all files necessary to run a container.
For creating docker image, docker needs a manual. This manual is called Dockerfile. Developer just needs to create this. Sounds cool!
Lets create a Dockerfile for our case.
#nodejs #docker #docker-beginner #docker-image #dockerfiles
1623863820
Dockerfile is basically a text file. It contains some set of instructions. Automation of docker image creation.
Docker Components =>
FROM: for a base image the command must be on top of the docker
RUN: To execute Command, it will create a layer in the image.
MAINTAINER: Author/owner/description
COPY: Copy files from the local system (docker VM) we need to provide a source, destination(We cant download file from the internet and any remote directory)
ADD: Similar to copy but, it provides a feature to download files from the internet, also we extract files at the docker image side.
EXPOSE: To Expose ports such as port 8080 for tomcat, port 80 for Nginx, etc.
WORKDIR: To set a working directory for a container.
CMD: Execute commands but during container creation
ENTRYPOINT: Similar to CMD, but has higher priority over CMD, first commands will be executed by ENTRYPOINT only.
#devops #docker #dockerfiles #containerization
1623780000
Introduction to docker basics with “Hello, world” in python
Dockerfile
Docker is an open-source platform that allows your code to run in an isolated environment from your infrastructure. It’s lightweight and takes care of all your dependencies. According to the Stack overflow developers survey of 2020, docker is the second most beloved platform after Linux and the most wanted platform for new developers.
In this article, we will be learning the basics of docker for beginners a step at a time. We are using python cause python is the most popular programming language and the distribution of python is the most horrible and docker helps to make it a tolerable process.
#dockerfiles #python3 #devops #docker
1623772740
Allowing docker container to share data or communicate between each other and outside application using few basic commands
docker file
Docker containers are like your babies. You made them, you take care of them, and you want to protect them from the outside world. Outside world is scary after all, all the bad things you can think of is in outside world. But as a mature parent you make a decision that you should be too restrictive. Docker allows you to explicitly expose little to the outside world as you need.
This article is in continuation to the below article. I assume that you know basics of creating docker file, starting and removing the images and containers. So kindly glance over the article below so we are on the same page.
#docker #devops #dockerfiles #container
1623757320
Prerequisite: https://bansalkushagra.medium.com/docker-architecture-o-s-virtualization-in-docker-a32ba4042215
Ø Docker runs on host O.S
Ø It is responsible for the running container to manage docker services.
Ø Docker daemons can communicate with other daemons.
Ø Docker users can interact with docker through a client.
Ø Docker Client uses commands and REST APIS to communicate with the docker daemon.
Ø When a Client runs any server command on the docker client terminal, the client terminals send these docker commands to the docker daemon.
Ø It is possible for Docker client to communicate with more than one daemon.
Ø It is used to provide an environment to execute and run applications. It contains the docker daemon, images, containers, networks, and Storage.
Ø It manages and Stores the docker Images.
Ø There are two types of registry in the docker.
o Public Registry
o Private Registry
Ø Docker images are the read-only binary templates used to create a container.
Ø Single files with all dependencies and configurations required to run a program.
#dockerfiles #devops-tool #devops #docker
1619257560
Kubernetes (K8s) is an open-source system for automating deployment, scaling, and management of containerized applications. So it’s a container orchestration tool, but it is just not limited to it as does storage orchestration, service discovery, load balancing, automated rollouts, brings in self-healing, provides secret and configuration management, provides horizontal scaling, and is a declarative way to define a cluster state.
Source: https://kubernetes.io/docs/concepts/overview/components/ (open source)
The biggest use-case for K8s is that it encourages micro-service based architecture. It does so by allowing micro-services to be independently scaled.
#docker #dockerfiles #kubernetes
1617969960
Docker is has become a common topic in the industry. It is a set of platform as a service (PaaS) products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries, and configuration files; they can communicate with each other through well-defined channels.This article will guide you through a quick overview of the Docker command.
Let’s start with running a Docker image. To run a docker image you use the command docker run ubuntu
. When you run the command what happens is, it runs the instance of the Ubuntu image and exists immediately.
If you list down the docker containers, docker ps
you will see there are no running containers. When you check all the docker containers docker ps -a
you will see that the container has started and stopped.
#dockerfiles #docker #devops-practice #devops-training #devops
1617936780
In the previous lessons, we learned about the anatomy of Docker images, how Docker containers work, how to create a Docker image from a Dockerfile, and learned a few characteristics of Docker images. However, we did not focus on sharing a Docker image with the world. In this lesson, we are going to learn just that as well as Docker image tags.
For this lesson, we are going to create a simple Docker image that prints a version number to the console when a container is created from it. The source code for this application is located in this GitHub repository.
docker-version-app/
├── .dockerignore
├── .gitignore
├── Dockerfile
└── version.txt
Our Docker image will look really simple. We are going to have a Dockerfile and version.txt
file that contains a version string. The Dockerfile has the CMD
instruction that prints the content of the version.txt
file. Since this operation doesn’t need a complicated setup, we will use the alpine:3.12.2
image as the parent image for our Docker image.
#programming #dockerhub #docker #dockerfiles #devops
1617882420
Today we will cover bellow things
**Prerequisites: **Before starting this article you must have knowledge of spring boot with Gradle dependencies. You can learn this from the below link
#docker-image #docker #dockerfiles #spring-boot #gradle
1615165740
After reading this article you will be able to build your entire project on Docker.
Docker is an open source platform for developing apps that enable separate your applications from your infrastructure.
The aim of this is quickly delivering software.
So the first step to dockerize your project begin with installing Docker.
sudo snap install docker
or
sudo apt install docker.io
#data-science #machine-learning #docker-compose #dockerfiles #docker
1614844980
Before starting I would like to recommend you to have a look at Docker in a nutshell if you are new to Docker. If not, you can continue this article.
In the previous Docker article (Docker in a nutshell), I showed you how to use commands and arguments in Docker commands. Now let’s check how to put commands and arguments into a pod-definition.yaml
file.
Look at this docker command.
docker run ubuntu sleep 5
Let’s see how to put the sleep 5
command and argument to the pod definition file.
#devops #dockerfiles #docker #kubernetes #cka-training
1611251100
Hello World! Today I’m about to share my notes and thoughts about Dockerfile
for Node.js
applications. I hope you will find it useful and create Dockerfile
, which will suit all your needs.
If you are here it means, that you have faced Docker
before, but to be sure that we are on the same page let’s remind what it is.
So, there are no secrets — Dockerfile
is an instruction of how our image will be built. Step by step, layer by layer this file describes how our image will look like.
Okay, so another question — what is an image? We can treat it as a template. Once you build an image from your Dockerfile
, it can be shared with other people. You can run a container from an image.
The last but not the least — container, it’s a running image, the actual process.
Why do we need this system? It solves the particular problem — environment. You can run a container where you need to, regardless of your OS. So, as you can see everything begins from Dockerfile
.
#nodejs #javascript #programming #dockerfiles #docker
1610401740
In this blog, we can see how to dockerize a simple python flask app and deploy it onto Heroku. This blog assumes that you have already installed Docker and Heroku in your PC. If that’s not the case, you can easily install it from here and here.
At First, create a new directory my-dir
and move inside the directory.
#python #docker #flask #dockerfiles