This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# use openjdk 16 image | |
FROM openjdk:16 | |
# copy the jar from host to container | |
ADD target/spring-app.jar app/spring-app.jar | |
# make app default directory for the upcoming commands | |
WORKDIR /app | |
# expose port 8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ java -jar target/spring-app.jar | |
. ____ _ __ _ _ | |
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ | |
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ | |
\\/ ___)| |_)| | | | | || (_| | ) ) ) ) | |
' |____| .__|_| |_|_| |_\__, | / / / / | |
=========|_|==============|___/=/_/_/_/ | |
:: Spring Boot :: (v2.5.0-SNAPSHOT) | |
[main] c.h.j.SpringApp : Starting SpringApp v0.0.1-SNAPSHOT | |
[main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ docker image build -t my-app . | |
[+] Building 0.2s (7/7) FINISHED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# use nginx as a base image | |
FROM nginx | |
# copy contents from host to nginx | |
COPY ./src/index.html /usr/share/nginx/html/index.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ echo "<h1 style='color:green'>Welcome :)</h1>" > /usr/share/nginx/html/index.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ docker container rm my-container | |
my-container |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ docker exec -it my-container bash | |
root@092246b4e808:/# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ | |
| docker host | | |
| ┏━━━━━━━━━━━━━━━━━┓| | |
[3000]---------»[80] my-container || | |
| ┗━━━━━━━━━━━━━━━━━┛| | |
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ docker container ls | |
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES | |
2a45998ad20d nginx "/docker-entrypoint.…" 6 minutes ago Up 6 minutes 80/tcp, 0.0.0.0:80->8080/tcp my-container |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ docker container run -d --name my-container -p 3000:80 nginx | |
ad4a816e7d2e1e104ac6285f770465a37a5417971f5cc99d8d7d04337b2542f0 |