Custom Fit - Docker
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Docker Installation Mac: [Docker Desktop for Mac](https://hub.docker.com/editions/community/docker-ce-desktop-mac) Windows: [Docker Desktop for Windows](https://hub.docker.com/editions/community/docker-ce-desktop-windows) Linux: ``` sudo apt-get update sudo apt-get upgrade sudo apt install docker.io sudo systemctl start docker sudo systemctl enable docker sudo systemctl status docker ``` :::spoiler **Installation Steps for Mac/Windows:** 1. Download Windows/Mac docker installable from above links. 2. Install dmg/exe files by following on-screen instructions and provide credentials If needed. **Installation Steps for Linux Ubuntu:** 1. Execute above commands in Linux Terminal. ::: # Docker Lab Setup > [color=#00bfff] **Linux Ubuntu VM Hostnames** ``` docker001.westeurope.cloudapp.azure.com docker002.westeurope.cloudapp.azure.com docker003.westeurope.cloudapp.azure.com .. .. docker009.westeurope.cloudapp.azure.com docker001.eastus.cloudapp.azure.com docker001.eastus2.cloudapp.azure.com docker001.westus.cloudapp.azure.com docker001.westus2.cloudapp.azure.com ``` > [color=#00bfff] **Connect From Windows/Mac** HostName: docker00X.westeurope.cloudapp.azure.com Username: ubuntu Password: DockerUser@123 ==Syntax:== ssh <username>@<hostname> > Example ```bash= ssh ubuntu@docker000.westeurope.cloudapp.azure.com ``` :::info :bulb: Note: Type 'yes' for 1st time login with ssh and enter password ::: :::spoiler **Mac:** 1. Open ==Terminal== and execute above commands **Windows:** 1. Connect from [Putty](https://www.putty.org/) or [Chrome Secure shell](https://chrome.google.com/webstore/detail/secure-shell-app/pnhechapfaindjhompbnflcldabbghjo/related?hl=en) User1. docker000.eastus.cloudapp.azure.com docker001654442.eastus.cloudapp.azure.com User2. docker002.eastus.cloudapp.azure.com docker003.eastus.cloudapp.azure.com User3. docker004.eastus.cloudapp.azure.com docker005.eastus.cloudapp.azure.com User4. docker006.eastus.cloudapp.azure.com docker007.eastus.cloudapp.azure.com User5. docker008.eastus.cloudapp.azure.com docker009.eastus.cloudapp.azure.com User6. docker000.eastus2.cloudapp.azure.com docker001.eastus2.cloudapp.azure.com User7. docker002.eastus2.cloudapp.azure.com docker003.eastus2.cloudapp.azure.com User8. docker004.eastus2.cloudapp.azure.com docker005.eastus2.cloudapp.azure.com User9. docker006.eastus2.cloudapp.azure.com docker007.eastus2.cloudapp.azure.com User10. docker008.eastus2.cloudapp.azure.com docker009.eastus2.cloudapp.azure.com User11. docker000.westus.cloudapp.azure.com docker001.westus.cloudapp.azure.com User12. docker002.westus.cloudapp.azure.com docker003.westus.cloudapp.azure.com User13. docker004.westus.cloudapp.azure.com docker005.westus.cloudapp.azure.com User14. docker006.westus.cloudapp.azure.com docker007.westus.cloudapp.azure.com User15. docker008.westus.cloudapp.azure.com docker009.westus.cloudapp.azure.com User16. docker000583293.westus2.cloudapp.azure.com docker001.westus2.cloudapp.azure.com User17. docker002.westus2.cloudapp.azure.com docker003.westus2.cloudapp.azure.com User18. docker004.westus2.cloudapp.azure.com docker005.westus2.cloudapp.azure.com User19. docker006.westus2.cloudapp.azure.com docker007.westus2.cloudapp.azure.com User20. docker008.westus2.cloudapp.azure.com docker009.westus2.cloudapp.azure.com User21. docker000.westeurope.cloudapp.azure.com docker001.westeurope.cloudapp.azure.com User22. docker002.westeurope.cloudapp.azure.com docker003.westeurope.cloudapp.azure.com User23. docker004.westeurope.cloudapp.azure.com docker005.westeurope.cloudapp.azure.com User24. docker006.westeurope.cloudapp.azure.com docker007.westeurope.cloudapp.azure.com User25. docker008.westeurope.cloudapp.azure.com docker009.westeurope.cloudapp.azure.com User26. docker000.northeurope.cloudapp.azure.com docker001.northeurope.cloudapp.azure.com User27. docker002.northeurope.cloudapp.azure.com docker003.northeurope.cloudapp.azure.com User28. docker004.northeurope.cloudapp.azure.com docker005.northeurope.cloudapp.azure.com User29. docker006.northeurope.cloudapp.azure.com docker007.northeurope.cloudapp.azure.com User30. docker008.northeurope.cloudapp.azure.com docker009.northeurope.cloudapp.azure.com ::: # Docker Validation ```bash= docker -v ``` ### Docker Hub URL: [Docker Hub URL](https://hub.docker.com/) gaptech # Run sample Docker Container **Docker Image:** gaptech/dockerdemo ```bash= docker pull gaptech/dockerdemo docker images docker container run -d -p 8082:80 --name my_first_container gaptech/dockerdemo docker ps -a ``` > Validation http://docker001.centralus.cloudapp.azure.com:8082 http://docker001.centralus.cloudapp.azure.com:8082/welcome.html # Play with Docker Commands > [color=#757575] Stop ```bash= docker container stop my_first_container ``` > [color=#66b032] Start ```bash= docker container start my_first_container ``` > [color=#ff0000] Remove ```bash= docker container rm -f my_first_container ``` # Container Lifecycle Commands ==Syntax:== docker container <container-state> <container-id> (or) <container-name> :::info Note: we can find container id using “docker ps –a ” command ::: :::spoiler > [color=#757575] Stop ```bash= docker container stop my_first_container ``` > [color=#66b032] Start ```bash= docker container start my_first_container ``` > [color=#3cd070] Restart ```bash= docker container restart my_first_container ``` > [color=#8b0000] Kill ```bash= docker container kill my_first_container ``` > [color=#ffb300] Pause ```bash= docker container pause my_first_container ``` > [color=#48d1cc] Unpause ```bash= docker container unpause my_first_container ``` > [color=#ff0000] Remove ```bash= docker container rm -f my_first_container ``` > [color=#ff0000] Remove All Containers ```bash= docker container rm -f $(docker ps -aq) ``` ::: # Portainer Docker Container > Installation ```bash= docker volume create portainer_data docker run -d -p 8000:8000 -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data --name portainer portainer/portainer ``` > Validation: http://docker001.centralus.cloudapp.azure.com:9000 # Other Docker Commands: :::spoiler >Login ```bash= docker login ``` Note: Enter docker hub credentials. Creds: gaptech/GapTech@123 >Logout ```bash= docker logout ``` >Logs ```bash= docker container logs –f <container-id> ``` Note: Running a container without detach flag show logs. >Info ```bash= docker info ``` Note: Display all docker information like containers running >Exec ```bash= docker container exec -it <container-id> /bin/bash ``` Note: To log into container bash Note: Enter “exit” command to get out from the container. ::: # Docker Environmental Variables :::info ==Syntax:== docker container run -d -p 8080:8080 -e key=value -e key=value --name image-name gaptech/dockerdemo ::: ## Run RabbitMQ Container with ENV’s > without ENV variables: ```bash= docker container run -d -p 8091:15672 --name rabbitmq rabbitmq:3-management ``` :::info RabbitMQ docker container will be launched with default creds i.e., guest/guest ::: > Validation: http://docker001.centralus.cloudapp.azure.com:8091 > with ENV variables: ```bash= docker container run -d -p 8092:15672 --name rabbitmq-with-env -e RABBITMQ\DEFAULT_USER=gaptech -e RABBITMQ_DEFAULT_PASS=gaptech rabbitmq:3-management ``` :::info Note: Note: RabbitMQ docker container will be launched with custom creds i.e., gaptech/gaptech ::: > Validation: http://docker001.centralus.cloudapp.azure.com:8092 # Docker Volumes ==Syntax:== docker volume create <docker-volume-name> :::info Example: docker volume create volume1 ::: ## Jenkins Docker Container ```bash= docker volume create jenkins_home docker run -p 8085:8080 -v jenkins_home:/var/jenkins_home --name jenkins jenkins/jenkins:lts ``` **Validation:** Jenkins should be accessible http://docker001.centralus.cloudapp.azure.com:8085/ > Case1: Remove the Container and Rerun the container ```bash= docker container rm -f jenkins docker run -p 8085:8080 -v jenkins_home:/var/jenkins_home --name jenkins jenkins/jenkins:lts ``` **Validation:** Previous Jobs should Exist http://docker001.centralus.cloudapp.azure.com:8085/ > Case2: Run another container without volume, different port & different container name ```bash= docker run -p 8086:8080 --name jenkins-without-volume jenkins/jenkins:lts ``` **Validation:** Fresh Jenkins setup in 8086 port http://docker001.centralus.cloudapp.azure.com:8085/ http://docker001.centralus.cloudapp.azure.com:8086/ # Build Spring Boot App as Docker Image GitHub - [Spring Boot App Source Code](https://github.com/gaptech/springbootapp.git) Step1: Open IntelliJ and Import the above project Step2: Build Jar by executing below command ```bash= ./gradlew clean build ``` Step3: create a file named “Dockerfile” in project root directory Step4: Write Dockerfile as below ```dockerfile= FROM openjdk:8 EXPOSE 8090 ADD build/libs/springbootapp-0.0.1-SNAPSHOT.jar springbootapp-0.0.1-SNAPSHOT.jar ENTRYPOINT ["java","-jar","/springbootapp-0.0.1-SNAPSHOT.jar"] ``` Step5: Modify parameters like port, jar name as per your configuration. (If needed) Step6: > **Way1:** If Docker Installed in Mac/Windows Open a terminal where Dockerfile folder resides. Example: ../../<project-name>/ ==Syntax:== docker build -t <docker-image-name> <docker-file-path> > **Example** ```bash= docker build -t gaptech/springbootapp . ``` ## Run Spring Boot Docker Container ``` bash= docker images docker container run -d -p 8090:8090 --name myspringbootapp gaptech/springbootapp docker ps -a ``` Validation: ```bash= URL: [http://docker001.centralus.cloudapp.azure.com:8090](http://localhost:8090/) URL: http://docker001.centralus.cloudapp.azure.com:8090/hellodocker ``` ## Pushing Docker Images to Docker Hub ```bash= Syntax: docker push <image-name> Example: docker push gaptech/springbootapp ``` Validate Docker Image from Docker Hub Docker Hub: https://hub.docker.com/ :::info Docker Hub Credentials: username: gaptech password: GapTech@123 ::: # Docker Compose :::spoiler [Docker Compose File GitLink](https://github.com/gaptech/DockerFiles/blob/master/docker-compose.yaml) ```bash= docker compose up –d ``` Note: File name should be docker-compose.yaml (or) docker-compose.yml Docker Compose - Example Example DockerCompose: [WordPress Docker Compose File](https://docs.docker.com/compose/wordpress/) Step1: create a file with docker-compose.yml and paste the above sample compose file Step2: Execute the below command ```bash= Command: docker-compose up -d ``` Step3: Validate Docker containers from UI ::: # Creating a Docker Swarm Cluster Step1: Get the IP address of VM using below command ```bash= curl ifconfig.co ``` Step2: ```bash= Syntax: docker swarm init --advertise-addr=<leader-node-ip-address> Example: docker swarm init --advertise-addr=192.168.0.23 ``` Step3: ```bash= docker swarm join --token <swarm-token> <leader-node-ip>:<generated-port> ``` Step4: ```bash= docker node ls ``` ## Deploy Docker Container in Swarm Cluster ```bash= Syntax: docker service create -d -p <port> --name <name-of-service> --replicas=<count> <image-name> Example1: docker service create -d -p 8090:8090 --name swarmtest --replicas=5 gaptech/dockerdemo Example2: docker service create -d -p 8091:80 --name springbootservice --replicas=5 gaptech/springbootapp ``` ```bash= Command: docker service ls ``` ```bash= Command: docker ps -a ``` ```bash= Syntax: docker service ps <service-name> Command: docker service ps swarmtest ``` ## Scaling Docker Services in Swarm Scaling UP ```bash= Syntax: docker service scale <service-name>=<new-count> Example: docker service scale swarmtest=10 ``` Scaling Down ```bash= Example: docker service scale swarmtest=2 ``` Removing ```bash= Example: docker service rm swarmtest ## Docker Stack File Docker Stack YAML File ```yaml= version: '3.3' services: myspringbootapp: image: gaptech/springbootapp:latest ports: \- 8090:8090/tcp deploy: replicas: 5 placement: constraints: \- node.hostname == master dockerdemo: image: gaptech/dockerdemo:latest ports: \- 8091:80/tcp deploy: replicas: 5 ``` ==Syntax:== docker stack deploy --compose-file <docker-yaml.yml> <stack-name> ```bash= docker stack deploy --compose-file docker-compose.yml centric ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully