• docker使用笔记


    查看本机上所有镜像

    docker images
    
    • 1

    打包项目(打包完成后自动载入镜像)

    The command docker build -t search-server . you provided is a standard way to build a Docker image. The -t flag tags the resulting image, and search-server is the tag (name) you’re assigning to the image. The . at the end of the command tells Docker to use the current directory for the build context, which should contain your Dockerfile.

    Here are some points to ensure and improve the build process:

    1. Dockerfile Quality: Make sure your Dockerfile is properly written, following best practices such as minimizing the number of layers, ordering multi-line arguments, and removing unnecessary files.

    2. Build Context: Only include necessary files in your build context directory to avoid sending a large context to the Docker daemon. You can use a .dockerignore file to exclude files and directories.

    3. Build Cache: Docker uses a build cache to speed up image creation. If you need to avoid using the cache, use the --no-cache flag.

    4. Multi-Stage Builds: If you have a complex build process, consider using multi-stage builds to keep your final image size small.

    5. Security: Remove any sensitive data from the Dockerfile and avoid using plain text credentials. Use secrets or environment variables where necessary.

    6. Image Size: Use slim or alpine versions of base images where possible to keep your image size small.

    7. Error Handling: Ensure that you have proper error handling and verification steps in your Dockerfile commands.

    If the image builds successfully without errors and works as expected, then your build command and Dockerfile are likely fine. However, if you are encountering issues or need specific improvements, you may need to adjust your Dockerfile or build command accordingly.

    docker build -t search-server .
    
    • 1

    导出docker后增加TAG(这一步好像不需要)

    docker tag 363fcdaf92c3 search-server:latest
    
    • 1

    导出镜像
    windows环境用这种方法导出很可能会造成linux下无法加载:

    docker save image-id > search-server.tar
    
    • 1

    docker save search-server:latest > search-server.tar
    
    • 1

    采用以下方式更加保险:

    docker save <image_name>:<tag> -o <output_file>.tar
    
    • 1

    docker save <image_id> -o <output_file>.tar
    
    • 1

    载入镜像

    docker load < search-server.tar
    
    • 1

    运行镜像

    docker run -p 4100:4100 search-server
    
    • 1

    让docker能够访问本机目录
    windows系统:

    docker run -v "E:/:/data" -p 4100:4100 search-server
    
    • 1

    linux系统:

    docker run -v "/:/data" -p 4100:4100 search-server
    
    • 1

    查看正在运行的docker

    docker ps
    
    • 1

    使用容器id或容器名来停止运行指定的镜像

    docker stop <container_id_or_name>
    
    • 1

    卸载镜像

    docker rm c75f653c4b23
    
    • 1

    删除镜像

    docker rmi 363fcdaf92c3
    
    • 1

    如果删不掉,可以用

    docker rmi -f 363fcdaf92c3
    
    • 1

    在CentOS 8中安装docker镜像:

    docker pull docker.elastic.co/elasticsearch/elasticsearch:7.17.18
    
    • 1

    运行该容器:

    docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.17.18
    
    • 1
  • 相关阅读:
    【已解决】Vue3+Element-plus中icon图标不显示的问题
    三、CAS原理与原子类
    来测测你的智力——智力题
    比较两组等数量等高度的结构间比值
    小白也会的校园网宽带拨号自动重连设置
    java类初始化及代码块加载顺序连根拔起
    思科模拟器:怎么连通几台3650交换机
    Android屏幕刷新机制
    传统企业如何实现数字化转型?
    【深度学习实验】线性模型(一):使用NumPy实现简单线性模型:搭建、构造损失函数、计算损失值
  • 原文地址:https://blog.csdn.net/dragon_T1985/article/details/136537564