docker安装镜像
CMD 容器启动命令
CMD指令用于为执行容器提供默认值。每个Dockerfile只有一个CMD命令,如果指定了多个CMD命令,那么只有最后一条会被执行,如果启动容器的时候指定了运行的命令,则会覆盖掉CMD指定的命令。
支持三种格式:
CMD ["executable","param1","param2"] (推荐使用)
CMD ["param1","param2"] (为ENTRYPOINT指令提供预设参数)
CMD command param1 param2 (在shell中执行)
ENTRYPOINT 入口点
ENTRYPOINT和CMD指令的目的一样,都是指定Docker容器启动时执行的命令,可多次设置,但只有最后一个有效。ENTRYPOINT不可被重写覆盖。
ENTRYPOINT、CMD区别:http://blog.csdn.net/newjueqi/article/details/51355510
https://segmentfault.com/q/1010000000417103
RUN是在Build时运行的,先于CMD和ENTRYPOINT。Build完成了,RUN也运行完成后,再运行CMD或者ENTRYPOINT。
ENTRYPOINT和CMD的不同点在于执行docker run时参数传递方式,CMD指定的命令可以被docker run传递的命令覆盖
ENTRYPOINT指定的参数比运行docker run时指定的参数更靠前
docker exec -it 容器id /bin/bash
java
#docker run
docker run java /bin/echo 'Hello World'
# dockerfile
# 基于哪个镜像
FROM java:8
# 将本地文件夹挂载到当前容器
VOLUME /tmp
# 拷贝文件到容器,也可以直接写成ADD xxxxx.jar /app.jar
ADD app.jar /app.jar
# 声明需要暴露的端口
EXPOSE 8761
# 配置容器启动后执行的命令
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
#以下在同一目录
#Dockerfile
FROM java:8
VOLUME /tmp
ADD microservice-discovery-eureka-0.0.1-SNAPSHOT.jar app.jar
# RUN bash -c 'touch /app.jar'
EXPOSE 9000
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
# docker-compose.yml
version: '2' # 表示该docker-compose.yml文件使用的是Version 2 file format
services:
eureka: # 指定服务名称
build: ./ # 指定Dockerfile所在路径
ports:
- "8761:8761" # 指定端口映射,类似docker run的-p选项,注意使用字符串形式
# 执行运行
docker-compose up -d
# --no-deps 标志可防止Compose重新创建任何web 依赖的服务
docker-compose up --no-deps -d web
#docker-compose
version: '2'
services:
mysql:
image: mysql:5.7
expose:
- "3306"
environment:
- MYSQL_ROOT_PASSWORD=123456
wordpress:
image: wordpress
ports:
- "80:80"
environment:
- WORDPRESS_DB_HOST=mysql
- WORDPRESS_DB_USER=root
- WORDPRESS_DB_PASSWORD=123456
nginx
docker run -d -p 91:91 nginx
docker exec -it nginx容器ID /bin/bash # 进入容器
#Nginx默认首页目录在:/usr/share/nginx/html/index.html
tee /usr/share/nginx/html/index.html <<-'EOF'
Welcome to docker
EOF
FROM nginx
RUN echo '<h1>Spring Cloud与Docker微服务实战</h1>' > /usr/share/nginx/html/index.html
FROM centos:7
RUN rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
RUN yum -y install nginx
RUN sed -i '1i\daemon off;' /etc/nginx/nginx.conf
ENTRYPOINT nginx
tomcat
https://my.oschina.net/u/3489495/blog/1825335
docker run --name tomcat8080 -d -p 8080:8080 tomcat
docker inspect -f '{{.Id}}' tomcat8080
docker exec -it a3d4f36dca98 /bin/bash
mysql
docker run -p 3309:3306 --name mysql3309 -e MYSQL_ROOT_PASSWORD=root -d mysql --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --default-authentication-plugin=mysql_native_password
#Docker-mysql8.0客户端无法连接
进入容器bash并进入mysql命令行
docker exec -it mysql3306 bash
root@eb3dbfb0958f:/# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
…
mysql>
//使用mysql数据库
mysql>use mysql
-- update user set authentication_string = password('root') where user = 'root';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'pass'; #更新一下用户的密码 root用户密码为newpassword
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
flush privileges;
CREATE USER 'liaozesong'@'%' IDENTIFIED WITH mysql_native_password BY 'Lzslov123!';
GRANT ALL PRIVILEGES ON *.* TO 'liaozesong'@'%';
//修改数据库
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
//刷新数据库
mysql> flush privileges;
dockerfile
FROM nginx_dockerfile:centos
RUN yum -y install gcc gcc-c++ make automake cmake
RUN groupadd mysql; useradd -r -M -u 39 -s /sbin/nologin -g mysql mysql
RUN mkdir /usr/local/mysql; mkdir /data/mysql/db -p
RUN yum install gcc gcc-c++ ncurses-devel bison bison-devel -y
RUN wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.29.tar.gz
RUN tar zxf mysql-5.6.29.tar.gz -C /usr/src/
WORKDIR /usr/src/mysql-5.6.29
RUN cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql/db -DSYSCONFDIR=/etc -DMYSQL_TCP_PORT=3306 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DEXTRA_CHARSETS=all -DDEFAULT_COLLATION=utf8_general_ci -DWITH-MYSQLD-LDFLAGS=-all-static -DWITH-CLIENT-LD-FLAGS=-all-static -DWITH_DEBUG=0 && gmake && gmake install
RUN chown -R root:mysql /usr/local/mysql/ && chown -R mysql:mysql /data/mysql/db/
RUN chmod 775 /usr/src/mysql-5.6.29/scripts/mysql_install_db.sh
RUN /usr/src/mysql-5.6.29/scripts/mysql_install_db.sh --basedir=/usr/local/mysql --datadir=/data/mysql/db --no-defaults --user=mysql
RUN cp /usr/src/mysql-5.6.29/support-files/my-default.cnf /etc/my.cnf
RUN cp /usr/src/mysql-5.6.29/support-files/mysql.server /etc/init.d/mysqld
RUN chmod -R 775 /etc/init.d/mysqld && /etc/init.d/mysqld start
RUN echo -e '#!/bin/bash\nexport PATH=$PATH:/usr/local/mysql/bin' >/etc/profile.d/mysql.sh
RUN source /etc/profile
docker build -t mysql_dockerfile:nginx_dockerfile .
https://www.cnblogs.com/ivictor/p/4832832.html
https://github.com/mysql/mysql-docker/blob/mysql-server/5.7/Dockerfile
FROM mysql:5.6.34
MAINTAINER fengzp <fengzp@gzyitop.com>
RUN apt-get update
RUN apt-get -y install vim
RUN usermod -u 1000 mysql
RUN mkdir -p /var/run/mysqld
RUN chmod -R 777 /var/run/mysqld
VOLUME /etc/mysql
VOLUME /script
https://www.cnblogs.com/andyfengzp/p/6424150.html