码头工人文件
# Start from the latest golang base image
FROM golang:latest
# Add Maintainer Info
LABEL maintainer="Sumit Thakur <sumitthakur@yahoo.com>"
# Set the Current Working Directory inside the container
WORKDIR /app
# Copy go mod and sum files
COPY go.mod go.sum ./
# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
RUN go mod download
# Copy the source from the current directory to the Working Directory inside the container
COPY . .
# Build the Go app
RUN go build -o testapp myapplication.go testapp.go
# Expose port 50051 / for internal comunication
ENV PORT 50051
RUN echo $PORT
EXPOSE ${PORT}
# Command to run the executable
CMD ["./testapp"]
构建 Docker 文件
docker build -t testapp -f Dockerfile .
这是完美的工作
运行 Docker 文件
docker run -d -p 50051:50051 testapp
这也可以正常工作
我检查正在运行的容器
docker ps
这会给我
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
57cd3c01bcda testapp "./testapp" 2 seconds ago Up 2 seconds 0.0.0.0:50051->50051/tcp gracious_bhaskara
当我检查网络检查时
docker network inspect bridge
SMILET
守候你守候我
哆啦的时光机
相关分类