본문 바로가기

후비고!

Mint 18.1 Docker 설치 및 운영

http://linuxbsdos.com/2016/12/13/how-to-install-docker-and-run-docker-containers-on-linux-mint-1818-1/



- sudo(root)  권한 없이 사용하기위해 사용자 권한 설정.

$ sudo service docker stop


$ sudo usermod -aG docker $USER


logout 이후 재접속.


$ sudo service docker start


$ docker images


REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

hello-world         latest              48b5124b2768        4 weeks ago         1.84 kB


$ docker run hello-world


$ docker images 


ubuntu image에서 bash 실행하기( 이미지를 찾을 수 없을경우 해당 이미지의 최종버전을 자동으로 다운로드 한다.)

$ docker run -it  ubuntu /bin/bash



대충 하다보니 처음에 이런새각이 들었다.."Docker 의 run 과 start/stop은 무엇이 다른가?" 해서 찾아보니 

Run : Image를 실행한다.(없을 경우 pull을 받을 수 있다.) 즉, image를 실행하고 해당 이미지기반의 컨테이너를 실행한다.

Start : 기 실행된 Image의 컨테이너의 시작/중지

..해서 뭔소리야!!! 라고 생각하지만 얼추 알아먹음.(이미지 시작 정보가 없으면 start/stop은 있을 수 없지 않으가???~)




우선 빠른 개발을 위해 이미지를 검색해보자

$ docker search spring 


NAME                                        DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED

bankmonitor/spring-boot                     Base image for Spring Boot apps                 28                   [OK]

springxd/base                               A base image for Spring XD Docker images        9                    [OK]

...


뭔가 많이 나온다... 안되겠다. 그냥 만들자!


계획수립 =>  우분투기반의 spring boot application, mysql, redis/memcached 이렇게 3개의 이미지면 될 듯하다.



Spring Boot 기반의 간단한 WebApplication을 만들자.

=> build.gradle

buildscript {

ext {

springBootVersion = '1.5.1.RELEASE'

}

repositories {

mavenCentral()

}

dependencies {

classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")

}

}


apply plugin: 'java'

apply plugin: 'eclipse'

apply plugin: 'org.springframework.boot'


jar {

baseName = 'docker-springapps'

version = '0.0.1'

}


sourceCompatibility = 1.8


repositories {

mavenCentral()

}



dependencies {

compileOnly('org.projectlombok:lombok')

compile("org.springframework.boot:spring-boot-starter-web")

testCompile("org.springframework.boot:spring-boot-starter-test")

}



=> EmployeeController

import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.PathVariable;

import org.springframework.web.bind.annotation.RestController;


import com.tistory.eclipse4j.entity.Employee;


@RestController

public class EmployeeController {


@GetMapping("/employees/{id}")

public Employee getHello(@PathVariable("id") Long id) {

return Employee.builder().id(id).name("홍길동").build();

}

}


=> http://localhost:8080/



=> Docker 이미지로 만들기


=> MySQL 연동하기

// MySql의 ip확인하기


$ docker inspect 32b2370dc49b(Container ID) | grep IP


            "LinkLocalIPv6Address": "",

            "LinkLocalIPv6PrefixLen": 0,

            "SecondaryIPAddresses": null,

            "SecondaryIPv6Addresses": null,

            "GlobalIPv6Address": "",

            "GlobalIPv6PrefixLen": 0,

            "IPAddress": "172.17.0.2",

            "IPPrefixLen": 16,

            "IPv6Gateway": "",

                    "IPAMConfig": null,

                    "IPAddress": "172.17.0.2",

                    "IPPrefixLen": 16,

                    "IPv6Gateway": "",

                    "GlobalIPv6Address": "",

                    "GlobalIPv6PrefixLen": 0,



운영중인 Docker Mysql 서버의 아이피는 172.17.0.2가 된다


좀 더~ 자세한 내용.

https://slipp.net/wiki/pages/viewpage.action?pageId=26640888


전체 소스

https://github.com/eclipse4j/springboot-docker