当前位置: 首页 > news >正文

厦门 网站开发企业网站建设的基本流程

厦门 网站开发,企业网站建设的基本流程,上海公司网站建设公司,微信电脑网站是什么原因在文章《Windows Docker笔记-Docker容器操作》中,已经成功创建了容器,也就是建好了工厂,接下来就应该要安装流水线设备,即运行项目达到生产的目的。 在Ubuntu容器中新建项目 这里要新建一个简单的C项目,步骤如下&…

在文章《Windows Docker笔记-Docker容器操作》中,已经成功创建了容器,也就是建好了工厂,接下来就应该要安装流水线设备,即运行项目达到生产的目的。

在Ubuntu容器中新建项目

这里要新建一个简单的C++项目,步骤如下:

1. 安装g++编译环境,

    1. 使用 docker start myUbuntu:启动myUbuntu容器
    1. 使用 docker ps -a:查看容器运行状态
    1. 使用 docker exec -it myUbuntu /bin/bash:进入容器终端
    1. 使用 apt-get update:更新软件包索引
    1. 使用 apt-get install g++:安装g++软件包
    1. 使用 g++ --version:查看安装的g++版本
D:\本周未完成工作\docker>docker start myUbuntu
myUbuntuD:\本周未完成工作\docker>docker ps -a
CONTAINER ID   IMAGE           COMMAND       CREATED        STATUS         PORTS     NAMES
da3b54c08bd5   ubuntu:latest   "/bin/bash"   18 hours ago   Up 3 seconds             myUbuntuD:\本周未完成工作\docker>docker exec -it myUbuntu /bin/bash
root@da3b54c08bd5:/# apt-get update
Get:1 http://archive.ubuntu.com/ubuntu noble InRelease [256 kB]
Get:2 http://security.ubuntu.com/ubuntu noble-security InRelease [126 kB]
>>>>>>>>>>>>>[此处省略部分过程代码]<<<<<<<<<<<<<<
Fetched 28.1 MB in 19s (1487 kB/s)
Reading package lists... Done
root@da3b54c08bd5:/# apt-get install g++
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
>>>>>>>>>>>>>[此处省略部分过程代码]<<<<<<<<<<<<<<
The following NEW packages will be upgraded:g++ g++-13 g++-13-x86-64-linux-gnu g++-x86-64-linux-gnu gcc libstdc++-13-dev
0 upgraded, 6 newly installed, 0 to remove and 12 not upgraded.
Need to get 14.6 MB of archives.
After this operation, 56.6 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
>>>>>>>>>>>>>[此处省略部分过程代码]<<<<<<<<<<<<<<
Setting up gcc (4:13.2.0-7ubuntu1) ...
Setting up libstdc++-13-dev:amd64 (13.3.0-6ubuntu2~24.04) ...
Setting up g++-13-x86-64-linux-gnu (13.3.0-6ubuntu2~24.04) ...
Setting up g++-x86-64-linux-gnu (4:13.2.0-7ubuntu1) ...
Setting up g++-13 (13.3.0-6ubuntu2~24.04) ...
Setting up g++ (4:13.2.0-7ubuntu1) ...
update-alternatives: using /usr/bin/g++ to provide /usr/bin/c++ (c++) in auto mode
update-alternatives: warning: skip creation of /usr/share/man/man1/c++.1.gz because associated file /usr/share/man/man1/g++.1.gz (of link group c++) doesn't exist
root@da3b54c08bd5:/# g++ --version
g++ (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.root@da3b54c08bd5:/#

到这里 g++ 编译环境就安装好了。

2. 安装vim

vim用来编辑代码文件使用。

root@da3b54c08bd5:/# apt-get install vim
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
>>>>>>>>>>>>>[此处省略部分过程代码]<<<<<<<<<<<<<<
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vim (vim) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vimdiff (vimdiff) in auto mode
Processing triggers for libc-bin (2.39-0ubuntu8.4) ...
root@da3b54c08bd5:/#vim --version
VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Jan 16 2025 20:13:18)
Included patches: 1-16, 647, 678, 697
Modified by team+vim@tracker.debian.org
Compiled by team+vim@tracker.debian.org
>>>>>>>>>>>>>[此处省略部分过程代码]<<<<<<<<<<<<<<

到这里 vim 编辑工具就安装好了。

3. 新建项目

这里的项目,直接使用文章《CMake项目中神器:CMakeLists.txt》中的第一个项目代码,如下图所示。

#include <iostream>int Func_Add(int num1, int num2)
{int nSum = num1 + num2;return nSum;
}int main()
{int numSum = Func_Add(2, 3);std::cout << "2 + 3 = " << numSum << std::endl;return 0;
}

步骤如下:

    1. 在/home/目录下新建test目录
    1. 在test目录中使用vim main.cpp:新建main.cpp文件
    1. 将上述代码编辑到main.cpp中
    1. 保存并退出文件
root@da3b54c08bd5:/# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@da3b54c08bd5:/# cd /home/
root@da3b54c08bd5:/home# ls
ubuntu
root@da3b54c08bd5:/home# mkdir test
root@da3b54c08bd5:/home# cd test/
root@da3b54c08bd5:/home/test# vim main.cpp
root@da3b54c08bd5:/home/test# cat main.cpp
#include <iostream>int Func_Add(int num1, int num2)
{int nSum = num1 + num2;return nSum;
}int main()
{int numSum = Func_Add(2, 3);std::cout << "2 + 3 = " << numSum << std::endl;return 0;
}
root@da3b54c08bd5:/home/test#

4. 编译项目并运行

    1. 使用g++命令编译项目文件
    1. 使用./可执行文件名 运行文件
root@da3b54c08bd5:/home/test# g++ -o main main.cpp
root@da3b54c08bd5:/home/test# ls
main  main.cpp
root@da3b54c08bd5:/home/test# ./main
2 + 3 = 5
root@da3b54c08bd5:/home/test#

代码此时已经正常运行了。运行的程序就相当于流水线设备,运行结果,就相当于到生产的玩具。

上述项目只是一个简单的例子,你可以把这个Ubuntu的容器当成一个Linux的开发环境来使用,在里面编译你实际的项目代码,然后运行。比使用虚拟机要好很多。非常的Nice

使用外部现有程序放到容器中运行

类比一下,上面的容器中新建项目运行相当于,工厂自己生产流水线设备,自给自足。另外一种情况是直接购买流水线设备,安装到工厂后直接运行。这种就相当于,将外部已经编译好的程序放到容器中运行一样。显然,docker也提供了这种方法,方便运维,这样容器就只提供运行环境就好,就不用提供编译开发环境,轻量了很多。

注意:以下操作需要先使用 e x i t 命令退出容器,在容器外部操作。 \color{red}{注意:以下操作需要先使用exit命令退出容器,在容器外部操作。} 注意:以下操作需要先使用exit命令退出容器,在容器外部操作。

这里文件演示,需要将上述生成的可执行文件 main 先保存到本地磁盘,然后删除到容器中的项目,在将本地可执行文件 main 导入容器中运行。

1. docker cp 命令说明

命令:docker cp 是 Docker 的一个命令,用于在容器和主机之间复制文件或文件夹。它类似于 Linux 的 cp 命令,但专门用于操作 Docker 容器中的文件。
格式:
docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH
docker cp [OPTIONS] SRC_PATH CONTAINER:DEST_PATH

  • CONTAINER:SRC_PATH:容器内的源文件路径。
  • DEST_PATH:主机上的目标路径。
  • SRC_PATH:主机上的源文件路径。
  • CONTAINER:DEST_PATH:容器内的目标路径。

常见用法

  1. 从容器复制文件到主机
    将容器中的文件复制到主机的指定路径:
    命令:docker cp <container_id>:/path/to/source/file /path/to/destination/on/host
    案例:docker cp my_container:/app/config.txt /home/user/config_backup.txt
  2. 从主机复制文件到容器
    将主机上的文件复制到容器的指定路径:
    命令:docker cp /path/to/source/file <container_id>:/path/to/destination/in/container
    案例:docker cp /home/user/new_config.txt my_container:/app/config.txt

1. 将编译好的可执行文件 main 保存到本地磁盘中

命令:docker cp myUbuntu:/home/test/main ./ # ./表示本地当前目录

root@da3b54c08bd5:/home/test# exit
exitD:\本周未完成工作\docker>docker ps -a
CONTAINER ID   IMAGE           COMMAND       CREATED        STATUS       PORTS     NAMES
da3b54c08bd5   ubuntu:latest   "/bin/bash"   20 hours ago   Up 2 hours             myUbuntuD:\本周未完成工作\docker>docker cp myUbuntu:/home/test/main ./
Successfully copied 18.4kB to D:\本周未完成工作\docker\.\D:\本周未完成工作\docker>dir驱动器 D 中的卷是 Data卷的序列号是 F6F0-A014D:\本周未完成工作\docker 的目录2025/02/07  15:39    <DIR>          .
2025/02/07  15:39    <DIR>          ..
2025/02/07  10:54            16,584 main
2025/01/20  17:34        75,203,584 ubuntu.tar2 个文件     75,220,168 字节2 个目录 382,717,251,584 可用字节D:\本周未完成工作\docker>

上述,退出容器后,使用docker cp 将容器中的main可执行文件保存到了本地目录:D:\本周未完成工作\docker 下面。

2. 清理容器中的项目相关文件

D:\本周未完成工作\docker>docker exec -it myUbuntu /bin/bash
root@da3b54c08bd5:/# cd /home/test/
root@da3b54c08bd5:/home/test# rm -rf *
root@da3b54c08bd5:/home/test# ls
root@da3b54c08bd5:/home/test#

3. 将本地编译好的可执行文件 main 导入容器中运行

命令:docker cp ./main myUbuntu:/home/test/

root@da3b54c08bd5:/home/test# exit
exitD:\本周未完成工作\docker>docker cp ./main myUbuntu:/home/test/
Successfully copied 18.4kB to myUbuntu:/home/test/D:\本周未完成工作\docker>docker exec -it myUbuntu /bin/bash
root@da3b54c08bd5:/# cd /home/test/
root@da3b54c08bd5:/home/test# ls
main
root@da3b54c08bd5:/home/test# ./main
2 + 3 = 5
root@da3b54c08bd5:/home/test#

可以看到,容器中有了运行环境,直接使用外部导入的程序,就可以运行了。

如果,项目较大,需要的以来很多,可以导入程序后,运行调试,根据报错信息安装依赖包即可。


上一章:Windows Docker笔记-Docker容器操作
下一章:Windows Docker笔记-制作、加载镜像

http://www.yidumall.com/news/73681.html

相关文章:

  • 找设计案例的网站免费注册个人网站不花钱
  • 微信手机网站设计6商品推广软文范例100字
  • 商城微信网站怎么做搜狗seo怎么做
  • 武汉专业网站建设推广第一站长网
  • java论坛网站建设网站制作公司高端
  • 购物网站运作培训机构招生方案
  • 鞍山市住房和城乡建设委员会网站公司搭建网站
  • 建设是哪里的搜索引擎优化的五个方面
  • 电子商务网站建设策划书的流程世界杯竞猜
  • 潍坊做网站哪家公司最好快速排名上
  • 公司网站开发费用账务处理搜索量排名
  • wordpress 高校官网引擎优化seo
  • 湖南英文网站建设网店运营基础知识
  • 可以下载的网站模板吗路由优化大师
  • 余姚企业网站建设营销课程培训都有哪些
  • 自己怎么注册一个网站如何优化网页
  • 外发加工网贴吧梧州网站seo
  • 公司查询网站查询系统中文搜索引擎网站
  • 网页设计表格seo什么意思简单来说
  • 网站域名到期叫百度一下你就知道首页官网
  • 做ic哪些网站好做seo推广公司哪家好
  • 网站开发过程有几个阶段域名ip查询查网址
  • 商业网站的建设流程全网推广平台有哪些
  • php网站后台密码破解工具网站后台用户名密码破解免费推广方法
  • 制作作品的软件seopeix
  • 电子商务网站建设网络营销有什么特点
  • 重庆装修设计公司排名湖南正规seo公司
  • 提升网站浏览量杭州seo顾问
  • 做3d建模贴图找哪个网站浙江网络推广公司
  • 做企业网站的公司网站排名软件优化