Illustration: Docker container security - disabling SSH for production environments.

[Dockerfile] How to Prevent Docker Container from SSHing

While SSH is a valuable tool for debugging and testing Docker containers, enabling it in production environments is not recommended due to security concerns. To disable SSH in a Docker container, it’s advisable to remove the SSH server during the image building process. One way to accomplish this is to remove the SSH server during the Docker image building process. For example, if you’re using the alpine base image, you can use the following Dockerfile: ...

[Nginx] Expose specified port for Nginx in Dockerfile

When we build a custom docker image based on nginx docker image, the default lisenting port will be 8080. However, port 8080 is a quite popular, so sometimes I want to give a different port for my service. The below snippet of code is the solution. FROM nginx COPY ./public/ /usr/share/nginx/html EXPOSE 1313 CMD ["/bin/sh", "-c", "sed -i 's/listen .*/listen 1313;/g' /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'"]

[Golang] Create Dockerfile for golang app

Containerizing the application is very popular nowadays and it makes the deployment so easy. This post will show how to create a Dockerfile for golang application. There are basically two steps in the Dockerfile: Build the golang program source code Containerize the golang app binary # Build source code FROM golang:1.18-alpine AS build WORKDIR /go/src/github.com/app COPY . . RUN go mod tidy RUN CGO_ENABLED=0 GOOS=linux go build -a -o main . # Containerize the binary FROM alpine COPY --from=build /go/src/github.com/app/main . EXPOSE 3500 CMD ["/main"] Exporting the port 3500 is because golang app listens to 3500. Here is just an example. ...

DigitalOcean Referral Badge
Sign up to get $200, 60-day account credit !