|
|
|
@@ -71,7 +71,9 @@ CMD /home/myuser/go/bin/gopls -listen=":7050" |
|
|
|
``` |
|
|
|
|
|
|
|
Firstly, we install all the dependencies and then create |
|
|
|
a user which will have access to the source code. |
|
|
|
a user which will have access to the source code. We pass |
|
|
|
the same user ID as our host user by using the MY_USER_ID |
|
|
|
as the build argument. |
|
|
|
|
|
|
|
Then we have to replicate the |
|
|
|
host path in the container and set that as our work directory. This is a quirk |
|
|
|
@@ -88,8 +90,8 @@ We will now build the image. |
|
|
|
mkdir -p go |
|
|
|
|
|
|
|
docker build \ |
|
|
|
--build-arg MY_PWD=${PWD} \ |
|
|
|
--build-arg=MY_USER_ID=${MY_USER_ID} \ |
|
|
|
--build-arg MY_PWD=$PWD \ |
|
|
|
--build-arg=MY_USER_ID=`id -u $USER` \ |
|
|
|
-t myapp:latest . |
|
|
|
``` |
|
|
|
|
|
|
|
@@ -100,10 +102,10 @@ Now we can expose this port to our host machine. |
|
|
|
|
|
|
|
```bash |
|
|
|
docker run -d --name "myapp" \ |
|
|
|
-u `id -u ${USER}` \ |
|
|
|
-e "GOPATH=${PWD}/go" \ |
|
|
|
-u `id -u $USER` \ |
|
|
|
-e "GOPATH=$PWD/go" \ |
|
|
|
-p 7050:7050 \ |
|
|
|
-v ${PWD}:${PWD} myapp:latest |
|
|
|
-v $PWD:$PWD myapp:latest |
|
|
|
``` |
|
|
|
|
|
|
|
Notice, that we also mount the host source in the container with the same path, |
|
|
|
@@ -130,8 +132,8 @@ For VSCode, you can add the following to your `settings.json` |
|
|
|
``` |
|
|
|
|
|
|
|
After adding this flag, you will now be able to edit your source with all the |
|
|
|
added benefits that come with a language server like autocompletion and |
|
|
|
autoformatting. |
|
|
|
added benefits that come with a language server like auto completion and |
|
|
|
auto formatting. |
|
|
|
|
|
|
|
Since this is an experimental feature, it might break (a lot). Do let me know |
|
|
|
in the comments if this was helpful for you. |