Dockerfile
defines an Docker image
docker-compose.yml
predefines Docker containers
# Show list all images
docker images
# Remove an image
docker image rm <id or name>
# Show running Containers
docker ps
# Show all containers
docker ps -a
# Remove a container
docker rm <id or name>
### cwd to directory of docker-compose.yml
# Run all containers in a compose file
docker-compose up -d
## -d means detach, it will run containers and detach from stdout
# Run a container
docker-compose up <name>
# Stop a container
docker-compose stop <name>
# Stop and remove a container
docker-compose down <name>
# Stop and remove all container
docker-compose down
An example of docker-compose.yml
eureka:
image: eureka-service
ports:
- "8761:8761"
zuul:
image: gs-routing-and-filtering/zuul
ports:
- "80:8080" # HOST_PORT:GUEST_PORT
environment:
- SPRING_APPLICATION_NAME=zuul-proxy
- "EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://eureka:8761/eureka/"
links:
- eureka
An example of docker-compose.dev.yml
(used for development )
eureka:
build: eureka-service # <======== look up Dockerfile in ./eureka-service directory
ports:
- "8761:8761"
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up
docker-compose.dev.yml
inherits docker-compose.yml
with additional possibility to build images locally and expose all containers ports for convenient development.
See more: Docs
Example: docker-compose.yml and docker-compose.dev.yml
buildscript {
ext {
springBootVersion = '1.5.8.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
+ classpath('se.transmode.gradle:gradle-docker:1.2')
}
}
apply plugin: 'java'
+apply plugin: 'docker'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'spring-boot-multitenant'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Camden.SR5'
}
}
dependencies {
compile('org.apache.commons:commons-lang3:3.0')
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-data-rest')
compile('org.springframework.cloud:spring-cloud-starter-eureka')
compile('org.springframework.boot:spring-boot-starter-web')
runtime('mysql:mysql-connector-java')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
+task buildDocker(type: Docker, dependsOn: build) {
+ // push = true
+ applicationName = jar.baseName
+ dockerfile = file('src/main/docker/Dockerfile')
+ doFirst {
+ copy {
+ from jar
+ into stageDir
+ }
+ }
+}
Run build: ./gradlew buildDocker -x test
-x test
means exclude run test task.
docker inspect <name|id> | grep -i ip