Build a go environment using Docker

This time, I built a go environment using Docker, which I have been studying recently.
  1. Create a Dockerfile

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.

  1. Create docker-compose.yml

'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}
  1. 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.

  2. 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

Build a go environment using Docker
[Go + Gin] I tried to build a Docker environment
Build a lightweight Fast API development environment using Docker
Build a Flask development environment at low cost using Docker
[Linux] Build a jenkins environment with Docker
[Linux] Build a Docker environment with Amazon Linux 2
Build a LAMP environment on your local Docker
Go (Echo) Go Modules × Build development environment with Docker
[Python] Build a Django development environment with Docker
[Mac] Build a Python 3.x environment at the fastest speed using Docker
Build a LAMP environment [CentOS 7]
Build a machine learning environment
Build a Python environment offline
Environment construction, Build -Go edition-
Build a Django development environment using pyenv-virtualenv on Mac
How to build a Django (python) environment on docker
Build a Python virtual environment using venv (Django + MySQL ①)
Build a Python environment on your Mac using pyenv
Build a Python development environment using pyenv on MacOS
Build a development environment with Poetry Django Docker Pycharm
Generate a Docker image using Fabric
Build a Django development environment with Docker! (Docker-compose / Django / postgreSQL / nginx)
Build a Docker environment that can use PyTorch and JupyterLab
[Memo] Build a development environment for Django + Nuxt.js with Docker
Build a deb file with Docker
Build a Go development environment with VS Code's Remote Containers
Build Mysql + Python environment with docker
[Django] Build a Django container (Docker) development environment quickly with PyCharm
Build PyPy execution environment with Docker
Create a Todo app with Django ① Build an environment with Docker
Build a python3 environment on CentOS7
How to build a LAMP environment using Vagrant and VirtulBox Note
Build a Chainer environment using CUDA and cuDNN on a p2 instance
Build a local development environment for Lambda + Python using Serverless Framework
Try using virtualenv, which can build a virtual environment for Python
The simplest way to build a Spleeter usage environment using Windows
How to build a Python environment using Virtualenv on Ubuntu 18.04 LTS
Build and try an OpenCV & Python environment in minutes using Docker
Create a development environment for Go + MySQL + nginx with Docker (docker-compose)
Build a Python execution environment using GPU with GCP Compute engine
[DynamoDB] [Docker] Build a development environment for DynamoDB and Django with docker-compose
Easily build a DNS server using Twisted
Easily build a development environment with Laragon
Build Jupyter Lab (Python) environment with Docker
How to build a sphinx translation environment
Using venv in Windows + Docker environment [Python]
Build a python environment on MacOS (Catallina)
Build a Tensorflow environment with Raspberry Pi [2020]
Building a virtual environment using homebrew + pyenv-virtualenv
pyenv-Building a pypy environment using virtualenv (MacOSX)
I created an Anaconda environment using Docker!
[Python] Create a Batch environment using AWS-CDK
I want to build a Python environment
Build a Fast API environment with docker-compose
Get a local DynamoDB environment with Docker
Build a python virtual environment with pyenv
Build a Python + OpenCV environment on Cloud9
Build a modern Python environment with Neovim
Use WebDAV in a Portable Docker environment
Build NGINX + NGINX Unit + MySQL environment with Docker
Build a Python + bottle + MySQL environment with Docker on RaspberryPi3! [Easy construction]