Getting Started with Docker using Spring Boot
mvn install
java -jar target/spring-boot-docker-0.1.0.jar
docker build --compress --force-rm -t {Docker_Hub_Username}/{Docker_Hub_RepoName}:{Tag} .
Example : docker build -t vinodjayachandran/spring-boot-docker:1.0 .
- On successful execution of above command, it will create a docker image in your local which you can verify with the below command. It will list the set of images on your machine.
docker images
- Run Docker image locally on a container with a name for the container.
Example : docker run -p 8080:8080 -t vinodjayachandran/spring-boot-docker:1.0 --name=MyTestContainer
- Verify if the container is up. Your image will be listed with status as up along with container id. Without the option --all it will list only running containers
Example
$ docker container ls --all
- Stop/Start the container with container id retrieved from Step 4. After stopping the container you verify again with commands from Step 4
Example
docker stop {CONTAINER ID}
docker start {CONTAINER ID}
- Rename container
docker rename {EXISTING CONTAINER NAME OR ID} NEW_NAME
- Delete container
docker rm {EXISTING CONTAINER NAME OR ID}
-
Push the docker image to docker hub/registry
$ docker login --username={userName} --password={pwd}
Providing password directly on CLI isn't recommended. From a security perspective, we can have the password stored in a file and provided at run time through stdin