dockerfile Golang图片

simple
FROM golang:1.11-alpine AS build
WORKDIR /src/
COPY main.go go.* /src/

RUN CGO_ENABLED=0 go build -o /bin/demo
FROM scratch
COPY --from=build /bin/demo /bin/demo ENTRYPOINT ["/bin/demo"]

# p.53 of 344
# The exact details of how this works don’t matter for now, but it uses a fairly standard build process for Go containers called multi-stage builds. 
# The first stage starts from an official golang container image, which is just an operating system (in this case Alpine Linux) with the Go language environment installed. 
# It runs the go build command to compile the main.go file we saw earlier.
# The result of this is an executable binary file named demo. The second stage takes a completely empty container image (called a scratch image, as in from scratch) 
# and copies the demo binary into it.
# Minimal Container Images
# Why the second build stage? Well, the Go language environment, and the rest of Alpine Linux, is really only needed in order to build the program. 
# To run the pro‐ gram, all it takes is the demo binary, so the Dockerfile creates a new scratch container to put it in. The resulting image is very small (about 6 MiB)—and 
# that’s the image that can be deployed in production.
# Without the second stage, you would have ended up with a container image about 350 MiB in size, 98% of which is unnecessary and will never be executed. 
# The smaller the container image, the faster it can be uploaded and downloaded, and the faster it will be to start up.
# Minimal containers also have a reduced attack surface for security issues. The fewer programs there are in your container, the fewer potential vulnerabilities.
# Because Go is a compiled language that can produce self-contained executables, it’s ideal for writing minimal (scratch) containers. 
# By comparison, the official Ruby con‐ tainer image is 1.5 GiB; about 250 times bigger than our Go image, and that’s before you’ve added your Ruby program!

dockerfile 在Ubuntu中使用dotnet核心和docker的HTTPS证书

clean_certs.sh
dotnet dev-certs https --clean
remove_old_cert.sh
rm ${HOME}/.aspnet/https/aspnetapp.pfx
create_certicate.sh
dotnet dev-certs https -ep ${HOME}/.aspnet/https/aspnetapp.pfx -p certificate_password
copy_to_ca_folder.sh
sudo cp aspnetapp.pfx /usr/local/share/ca-certificates/
update_certs.sh
sudo update-ca-certificates
Dockerfile
#!/bin/bash

# Build with
# docker build -t api_image:dev -f .\Api.Dockerfile .
# docker push my_image:dev
# docker build -t react_image:dev -f .\Frontend.Dockerfile .
# docker push react_image:dev

docker pull api_image:dev
docker pull react_image:dev
docker container rm --force api_container || true
docker container rm --force react_container || true

docker container run -d \
        -p 80:80 \
        -p 443:443 \
        --network docker_network \
        -e ASPNETCORE_ENVIRONMENT=Development \
        -e ASPNETCORE_URLS="https://+443;http://+80" \
        -e ASPNETCORE_HTTPS_PORT=443 \
        -e ASPNETCORE_Kestrel__Certificates__Default__Password="certificate_password" \
        -e ASPNETCORE_Kestrel__Certificates__Default__Path="/https/aspnetapp.pfx" \
        -v "/usr/local/share/ca-certificates/:/https/" \
        --name api_container \
        api_image:dev

docker container run -d \
        -p 3000:3000 \
        --network docker_network \
        --name react_container \
        react_image:dev

dockerfile docker stack使用compose文件进行部署

docker stack deploy
docker stack deploy local-erised  --compose-file=docker-compose.yml 

dockerfile docker-compose mongo-rabbit-mongoexpres

Docker - Mongo DB Compose File
version: '3.1'
services:
 mongo:
   image: mongo
   restart: always
   environment:
     MONGO_INITDB_ROOT_USERNAME: root
     MONGO_INITDB_ROOT_PASSWORD: example
   ports:
     - 27017:27017
 mongo-express:
   image: mongo-express
   restart: always
   ports:
     - 8081:8081
   environment:
     ME_CONFIG_MONGODB_ADMINUSERNAME: root
     ME_CONFIG_MONGODB_ADMINPASSWORD: example
 rabbitmq:
   image: "rabbitmq:3-management"
   ports:
     - 15672:15672
     - 5672:5672

dockerfile docker运行RabbitMq

Rabbit
sudo docker run -p 15672:15672 -p 5672:5672 -d rabbitmq:3-management

dockerfile docker container에프록시추가하기

[dockerfile프록시설정] #docker #proxy

dockerfile
ENV http_proxy "http://168.219.61.252:8080"
ENV https_proxy "http://168.219.61.252:8080"

dockerfile 春季启动

春季启动

Dockerfile
FROM anapsix/alpine-java
RUN mkdir -p /usr/springboot
COPY ./target/api-0.0.1-SNAPSHOT.jar /usr/springboot
WORKDIR /usr/springboot
EXPOSE 8080
CMD ["java", "-jar", "api-0.0.1-SNAPSHOT.jar"]

dockerfile docker学习

docker
// 查看镜像
docker images 

// Remove one or more containers
docker rm containerid

// Remove one or more images
docker rmi imageid
docker rm image 4c108a37151f

// 运行镜像
sudo docker run -itd --name ubuntu ubuntu:latest /bin/bash

// 进入容器
sudo docker exec -it ubuntu bash

// 查看容器
docker ps -a

// 保存容器
sudo docker save ubuntu > ubuntu_save.tar

// 导出容器
sudo docker export ubuntu > ubuntu_export.tar

// 加载容器
sudo docker load < ubuntu_save.tar

// 导入容器
cat ubuntu_export.tar | sudo docker import - ubuntu:18.04

dockerfile Docker命令

Dockerfile
FROM

The base image for building a new image. This command must be on top of the dockerfile.

MAINTAINER

Optional, it contains the name of the maintainer of the image.

RUN

Used to execute a command during the build process of the docker image.

ADD

Copy a file from the host machine to the new docker image. There is an option to use an URL for the file, docker will then download that file to the destination directory.

ENV

Define an environment variable.

CMD

Used for executing commands when we build a new container from the docker image.

ENTRYPOINT

Define the default command that will be executed when the container is running.

WORKDIR

This is directive for CMD command to be executed.

USER

Set the user or UID for the container created with the image.

VOLUME

Enable access/linked directory between the container and the host machine.

dockerfile Jenkins-Artifactory-Gitlab拓扑

docker-compose.yaml
version: '3.5'
services:
  jenkins:
    build: jenkins
    #image: jenkins/jenkins:lts
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
      - "./jenkins/jenkins_home:/var/jenkins_home"
    ports:
      - '8080:8080'
      - '50000:50000'
    networks:
      - toxic_network

  gitlab:
    image: gitlab/gitlab-ce:latest
    volumes: 
      - ./gitlab/data:/etc/gitlab
      - ./gitlab/logs:/var/log/gitlab
      - ./gitlab/config:/var/opt/gitlab
    ports:
      - '80:80'
      - '22:22'
    networks:
      - toxic_network

  artifactory:
    image: docker.bintray.io/jfrog/artifactory-oss:latest
    ports:
      - '8081:8081'
    networks:
      - toxic_network

volumes:
  maven-repository:

networks: 
  toxic_network:
    name: toxic_network
    driver: bridge
JenkinsDockerfile
FROM jenkins/jenkins:lts

USER root
RUN apt-get update && apt-get install -y python3-pip
RUN curl -sSL https://get.docker.com/ | sh
RUN usermod -aG docker jenkins
ENV DOCKER_HOST unix:///var/run/docker.sock
USER jenkins
RUN pip3 install awscli --upgrade --user
RUN export PATH=$PATH:~/.local/bin/