DEV Community

loading...

5/28 TIL: Docker Compose, Volumes, cURL

David Hwang
・2 min read

Docker-compose


version: '3'
  services:
    server:
      build: .
      volumes:
        - .:/app
      ports:
        - 9090:9090
      command: ['wait-for-it.sh', 'db:3306', '--', 'air']
      depends_on:
        - db
    db:
      image: mysql
      restart: always
      environment:
        MYSQL_USER: admin
        MYSQL_PASSWORD: password
        MYSQL_ROOT_PASSWORD: password
        MYSQL_DATABASE: sampleDb
      ports:
        - '3306:3306'
      volumes:
        - mysql_db:/var/lib/mysql
      command:
        [
          'mysqld',
          '--character-set-server=utf8mb4',
          '--collation-server=utf8mb4_unicode_ci',
        ]
  volumes:
    mysql_db:
Enter fullscreen mode Exit fullscreen mode
  • Two containers: server & db
  • server
    • builds the Dockerfile in the current path
    • runs on port 9090 on both the host and within the container
    • executes 'wait-for-it.sh' to wait on the availability of port 3306 before running 'air'--using wait-for-it.sh is just an example and this shell script has to be installed as part of the Dockerfilehttps://github.com/vishnubob/wait-for-it
    • depends on db container
  • db

cURL & its flags

  • curl is a tool to transfer data from or to a server, using one of the supported protocols (FTP, HTTP, SFTP, and many more)
  • Example:

RUN curl -fLo [install.sh](http://install.sh/) [https://raw.githubusercontent.com/cosmtrek/air/master/install.sh](https://raw.githubusercontent.com/cosmtrek/air/master/install.sh)

Enter fullscreen mode Exit fullscreen mode
  • -f allows the HTTP to fail silently on server errors
  • -L will make curl redo the request on the new place if the server reports that the requested page has moved to a different location
  • -o writes the output to the specified file
  • -s is silent mode
  • -S is used with -s and it makes curl show an error message if it fails. ex) -sSfL

Discussion (0)