The other day, I made a remote container using a simple method in Go language (Reference: Environment construction with VSCode + Remote Container (go edition)), but after making it, LGTM from the master of the mind (@MegaBlackLabel) Along with the following ~~ Tsukkomi ~~ Revelation.
Good.
& mdash; Reina @ Bottomless Swamp Witch (@MegaBlackLabel) December 21, 2020
I think it would be nice to attach volume to the src folder in the project while replacing it with docker-compose in the next step.
A few days later, the government reached the point of making an app in earnest, and it became clear that the environment ahead was not enough, so I faced this issue again and created an environment like that, so I will summarize it again. ..
-1. Prerequisite environment -2. Create Working Folder -3. Create file for container -4. Create container configuration file for remote -5. Start Container
Other than this, basically no preparation is required. If you don't know how to install Remote --containers, refer to the above (VSCode + Remote Container environment construction (go)).
We have confirmed the operation on Windows 10 (Pro), but there is probably no problem with other OS including home (WSL2 is required separately for home).
This time, the configuration is roughly as follows (except for ".devcontainer", the folder name is arbitrary).
go-proj
├─ .devcontainer
│ └─ devcontainer.json
├─ docker
│ └─ go
│ └─ Dockerfile
├─ src
└─ docker-compose.yml
Create under the top directory. Each file will be described in the following items.
If you change the folder structure, change it accordingly.
docker-compose.yml
(If you make it according to this article, under the top directory "go-proj")
docker-compose.yml
version: '3.8'
services:
app:
build: ./docker/go/
command: /bin/sh -c "while sleep 1000; do :; done"
ports:
- 8080:8080
volumes:
- ./src:/go/src:cached
Dockerfile
(If you make it according to this article, under "go-proj/docker/go")
Dockerfile
#Latest at the time of writing this article
FROM golang:1.15
WORKDIR /go/src
ENV GO111MODULE=on
ENV GOPATH /go
RUN go get -v \
golang.org/x/tools/gopls \
github.com/ramya-rao-a/go-outline \
github.com/sqs/goreturns
devcontainer.json
(If you make it according to this article, under "go-proj/.devcontainer")
devcontainer.json
{
"name": "go",
"dockerComposeFile": [
"../docker-compose.yml"
],
"service": "app",
"workspaceFolder": "/go/src",
"settings": {
"terminal.integrated.shell.linux": null,
"go.gopath": "/go"
},
"extensions": [
"golang.go",
],
"shutdownAction": "stopCompose"
}
Open the project folder with VSCode and execute Remote-Containers: Reopen in Container
from the command palette and others.
Building a development environment with Go + echo + Docker + VSCode + Remote Containers (supports hot reload and step execution): Referenced halfway (Progress according to this procedure is currently used in the maintenance of realize) Not possible). As an aside, the author builds with realize → air (and echo → gin).
Recommended Posts