Making Docker and Deployment Process
Step:
set up your docker environment
build a image of activeMQ with Dockerfile
build a image of swieApp with Dockerfile
delploy your project with docker-compose.yml
一.Set up your docker environment
Install Docker CE
Before you install Docker CE for the first time on a new host machine, you need to set up the Docker repository. Afterward, you can install and update Docker from the repository.
1.SET UP THE REPOSITORY
1. Update the apt package index:
$ sudo apt-get update
2. Install packages to allow apt to use a repository over HTTPS:
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
3. Add Docker’s official GPG key:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
(Verify that you now have the key with the fingerprint 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88, by searching for the last 8 characters of the fingerprint.
$ sudo apt-key fingerprint 0EBFCD88
pub 4096R/0EBFCD88 2017-02-22
Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid Docker Release (CE deb) <docker@docker.com>
sub 4096R/F273FCD8 2017-02-22)
4. Use the following command to set up the stable repository.
$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
2.INSTALL DOCKER CE
1. Update the apt package index.
$ sudo apt-get update
2. Install the latest version of Docker CE, or go to the next step to install a specific version:
$ sudo apt-get install docker-ce
3. To install a specific version of Docker CE, list the available versions in the repo, then select and install:
a. List the versions available in your repo:
$ apt-cache madison docker-ce
b. Install a specific version using the version string from the second column, for example, 5:18.09.1~3-0~ubuntu-xenial.
$ sudo apt-get install docker-ce=5:18.09.1~3-0~ubuntu-xenial
4. Verify that Docker CE is installed correctly by running the hello-world image.
$ sudo docker run hello-world
(This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.)
二.Build a image of activeMQ with Dockerfile
1. Edit Dockerfile
Create an empty directory. Change directories (cd) into the new directory, create a file called Dockerfile, copy-and-paste the following content into that file, and save it. Take note of the comments that explain each statement in your new Dockerfile.
# Use an official jdk runtime as a parent image
FROM openjdk:8
# Copy the current directory contents into the container at /usr/src/apache
COPY . /usr/src/apache
# Set the working directory to /usr/src/apache
WORKDIR /usr/src/apache
# Make port 1884/61616/8161/5672/61613/1883/61614 available to the world outside this container
EXPOSE 1884
EXPOSE 61616
EXPOSE 8161
EXPOSE 5672
EXPOSE 61613
EXPOSE 1883
EXPOSE 61614
# Start the activemq service when the container launches
ENTRYPOINT ./apache-activemq-5.15.3/bin/linux-x86-64/activemq start && /bin/bash
This Dockerfile refers to a package of apache-activemq-5.15.3 we haven’t created yet, namely apache-activemq-5.15.3. Let’s create it next.
2. Copy the package of activemq to the current directory
Put the package of activemq in the same folder with the Dockerfile. This completes our service of activemq, which as you can see is quite simple. When the above Dockerfile is built into an image, apache-activemq-5.15.3 is present because of that Dockerfile’s COPY command, and the output from activemq is accessible over HTTP thanks to the EXPOSE command.
3. Build the app into a image
a. We are ready to build the app. Make sure you are still at the top level of your new directory. Here’s what ls should show:
$ ls
Dockerfile apache-activemq-5.15.3
b. Now run the build command. This creates a Docker image, which we’re going to name using the --tag option. Use -t if you want to use the shorter option.
$ docker build --tag=activemq . (dont't forget the dot ".", this means make it in the current directory)
c. Where is your built image? It’s in your machine’s local Docker image registry:
$ docker image ls
REPOSITORY TAG IMAGE ID
activemq latest 326387cea398
Note how the tag defaulted to latest. The full syntax for the tag option would be something like --tag=activemq:v0.0.1.
4. Test whether the image was created successfully
We test whether the image was created successfully by creating a container.
a. Now let’s run the app in the background, in detached and interactive mode:
$ docker run -d -i -p 4000:1884 activemq
-i --interactive Keep STDIN open even if not attached
-d --detach Run container in background and print container ID
-p --publish-all Publish all exposed ports to random ports