latest
RUN mkdir /go/src/charts_server && apt-get update && apt-get install \
-y vim
WORKDIR /go/src/charts_server
ADD . /go/src/charts_server
・ FROM golang: latest Based on the latest version of golang.
· RUN mkdir / go / src / charts_server && apt-get update && apt-get install \ -y vim Create a work place with mkdir. Also install the editor.
・ WORKDIR / go / src / charts_server Changed the execution directory of Docker instruction to / go / src / charts_server.
・ ADD. / Go / src / charts_server Copy the current directory to / go / src / charts_server.
'3'
services:
app:
build: .
tty: true
volumes:
- ./work:/go/src/charts_server
ports:
- "8080:8080"
depends_on:
- mysql
mysql:
image: mysql:latest
container_name: mysql_charts_container
environment:
MYSQL_ROOT_PASSWORD: ${ROOTPASS}
MYSQL_DATABASE: ${DATABASE}
MYSQL_USER: ${USERNAME}
MYSQL_PASSWORD: ${USERPASS}
After creating the above file, execute the following command in the terminal $docker-compose up -d The environment is built based on the description contents of Dockerfile and docker-compose.yml.
Execute the command to enter the created Docker container Run $ docker exec -it charts_server_app_1 / bin / bash to get inside the container
You can put it in the container by entering the above command. I am mounting / go / src / charts_server in the container to the work directory. Therefore, if you add a folder or file to / go / src / charts_server, it will also be added to the mounted work directory.
Impressions This time, I used Docker to build the environment for go. It was quite difficult. I've built the environment for python many times, so it's quick, but this time it took time. Although I had a hard time, once I built the environment with Docker, I can distribute it to other people, and I think that the merit is great because it does not take the same time to build the environment. And best of all, it's pretty nice to be able to use go inside Docker without having to install go inside the pc. (It doesn't make sense because I don't collaborate with anyone ...)
The following are the references I used when building the environment. Data Scientist Kame-san's blog : Easy to understand and recommended. Building a Golang environment using docker : I almost imitated it.
Recommended Posts